1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum CompletionShell {
10 Bash,
11 Zsh,
12 Fish,
13}
14
15#[derive(Debug, Clone, PartialEq, Eq)]
17pub enum CompletionShellError {
18 Unsupported { shell: String },
20}
21
22pub fn parse_completion_shell(s: &str) -> Result<CompletionShell, CompletionShellError> {
26 match s {
27 "bash" => Ok(CompletionShell::Bash),
28 "zsh" => Ok(CompletionShell::Zsh),
29 "fish" => Ok(CompletionShell::Fish),
30 other => Err(CompletionShellError::Unsupported {
31 shell: other.to_string(),
32 }),
33 }
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn parse_known_shells() {
42 assert_eq!(parse_completion_shell("bash"), Ok(CompletionShell::Bash));
43 assert_eq!(parse_completion_shell("zsh"), Ok(CompletionShell::Zsh));
44 assert_eq!(parse_completion_shell("fish"), Ok(CompletionShell::Fish));
45 assert!(matches!(
46 parse_completion_shell("BASH"),
47 Err(CompletionShellError::Unsupported { .. })
48 ));
49 assert!(matches!(
50 parse_completion_shell("powershell"),
51 Err(CompletionShellError::Unsupported { shell }) if shell == "powershell"
52 ));
53 }
54}