clap/completions/
shell.rs1#[allow(deprecated, unused_imports)]
2use std::ascii::AsciiExt;
3use std::str::FromStr;
4use std::fmt;
5
6#[cfg_attr(feature = "lints", allow(enum_variant_names))]
8#[derive(Debug, Copy, Clone)]
9pub enum Shell {
10 Bash,
12 Fish,
14 Zsh,
16 PowerShell,
18 Elvish,
20}
21
22impl Shell {
23 pub fn variants() -> [&'static str; 5] { ["zsh", "bash", "fish", "powershell", "elvish"] }
25}
26
27impl FromStr for Shell {
28 type Err = String;
29
30 fn from_str(s: &str) -> Result<Self, Self::Err> {
31 match s {
32 "ZSH" | _ if s.eq_ignore_ascii_case("zsh") => Ok(Shell::Zsh),
33 "FISH" | _ if s.eq_ignore_ascii_case("fish") => Ok(Shell::Fish),
34 "BASH" | _ if s.eq_ignore_ascii_case("bash") => Ok(Shell::Bash),
35 "POWERSHELL" | _ if s.eq_ignore_ascii_case("powershell") => Ok(Shell::PowerShell),
36 "ELVISH" | _ if s.eq_ignore_ascii_case("elvish") => Ok(Shell::Elvish),
37 _ => Err(String::from("[valid values: bash, fish, zsh, powershell, elvish]")),
38 }
39 }
40}
41
42impl fmt::Display for Shell {
43 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44 match *self {
45 Shell::Bash => write!(f, "BASH"),
46 Shell::Fish => write!(f, "FISH"),
47 Shell::Zsh => write!(f, "ZSH"),
48 Shell::PowerShell => write!(f, "POWERSHELL"),
49 Shell::Elvish => write!(f, "ELVISH"),
50 }
51 }
52}