]> git.proxmox.com Git - rustc.git/blob - vendor/clap/src/completions/shell.rs
New upstream version 1.59.0+dfsg1
[rustc.git] / vendor / clap / src / completions / shell.rs
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 #[derive(Debug, Copy, Clone)]
8 pub enum Shell {
9 /// Generates a .bash completion file for the Bourne Again SHell (BASH)
10 Bash,
11 /// Generates a .fish completion file for the Friendly Interactive SHell (fish)
12 Fish,
13 /// Generates a completion file for the Z SHell (ZSH)
14 Zsh,
15 /// Generates a completion file for PowerShell
16 PowerShell,
17 /// Generates a completion file for Elvish
18 Elvish,
19 }
20
21 impl Shell {
22 /// A list of possible variants in `&'static str` form
23 pub fn variants() -> [&'static str; 5] {
24 ["zsh", "bash", "fish", "powershell", "elvish"]
25 }
26 }
27
28 impl FromStr for Shell {
29 type Err = String;
30
31 #[cfg_attr(feature = "cargo-clippy", allow(clippy::wildcard_in_or_patterns))]
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 {
47 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 }