#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompletionShell {
Bash,
Zsh,
Fish,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CompletionShellError {
Unsupported { shell: String },
}
pub fn parse_completion_shell(s: &str) -> Result<CompletionShell, CompletionShellError> {
match s {
"bash" => Ok(CompletionShell::Bash),
"zsh" => Ok(CompletionShell::Zsh),
"fish" => Ok(CompletionShell::Fish),
other => Err(CompletionShellError::Unsupported {
shell: other.to_string(),
}),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parse_known_shells() {
assert_eq!(parse_completion_shell("bash"), Ok(CompletionShell::Bash));
assert_eq!(parse_completion_shell("zsh"), Ok(CompletionShell::Zsh));
assert_eq!(parse_completion_shell("fish"), Ok(CompletionShell::Fish));
assert!(matches!(
parse_completion_shell("BASH"),
Err(CompletionShellError::Unsupported { .. })
));
assert!(matches!(
parse_completion_shell("powershell"),
Err(CompletionShellError::Unsupported { shell }) if shell == "powershell"
));
}
}