1 #[allow(deprecated, unused_imports)] 2 use std::ascii::AsciiExt; 3 use std::fmt; 4 use std::str::FromStr; 5 6 /// Describes which shell to produce a completions file for 7 #[cfg_attr(feature = "lints", allow(enum_variant_names))] 8 #[derive(Debug, Copy, Clone)] 9 pub enum Shell { 10 /// Generates a .bash completion file for the Bourne Again SHell (BASH) 11 Bash, 12 /// Generates a .fish completion file for the Friendly Interactive SHell (fish) 13 Fish, 14 /// Generates a completion file for the Z SHell (ZSH) 15 Zsh, 16 /// Generates a completion file for PowerShell 17 PowerShell, 18 /// Generates a completion file for Elvish 19 Elvish, 20 } 21 22 impl Shell { 23 /// A list of possible variants in `&'static str` form variants() -> [&'static str; 5]24 pub fn variants() -> [&'static str; 5] { 25 ["zsh", "bash", "fish", "powershell", "elvish"] 26 } 27 } 28 29 impl FromStr for Shell { 30 type Err = String; 31 from_str(s: &str) -> Result<Self, Self::Err>32 fn from_str(s: &str) -> Result<Self, Self::Err> { 33 match s { 34 "ZSH" | _ if s.eq_ignore_ascii_case("zsh") => Ok(Shell::Zsh), 35 "FISH" | _ if s.eq_ignore_ascii_case("fish") => Ok(Shell::Fish), 36 "BASH" | _ if s.eq_ignore_ascii_case("bash") => Ok(Shell::Bash), 37 "POWERSHELL" | _ if s.eq_ignore_ascii_case("powershell") => Ok(Shell::PowerShell), 38 "ELVISH" | _ if s.eq_ignore_ascii_case("elvish") => Ok(Shell::Elvish), 39 _ => Err(String::from( 40 "[valid values: bash, fish, zsh, powershell, elvish]", 41 )), 42 } 43 } 44 } 45 46 impl fmt::Display for Shell { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result47 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 48 match *self { 49 Shell::Bash => write!(f, "BASH"), 50 Shell::Fish => write!(f, "FISH"), 51 Shell::Zsh => write!(f, "ZSH"), 52 Shell::PowerShell => write!(f, "POWERSHELL"), 53 Shell::Elvish => write!(f, "ELVISH"), 54 } 55 } 56 } 57