1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use core::hint::unreachable_unchecked;
use structopt::clap::{self, Shell::*};
#[derive(Debug, Copy, Clone)]
pub struct Shell(pub clap::Shell);
impl Shell {
pub unsafe fn parse_from_str_unchecked(text: &str) -> Self {
Shell(match text {
"bash" => Bash,
"fish" => Fish,
"zsh" => Zsh,
"powershell" => PowerShell,
"elvish" => Elvish,
_ => unreachable_unchecked(),
})
}
pub fn to_clap(self) -> clap::Shell {
self.0
}
pub fn from_clap(clap: clap::Shell) -> Self {
Shell(clap)
}
}
impl PartialEq for Shell {
fn eq(&self, other: &Self) -> bool {
match (self.0, other.0) {
(Bash, Bash)
| (Fish, Fish)
| (Zsh, Zsh)
| (PowerShell, PowerShell)
| (Elvish, Elvish) => true,
_ => false,
}
}
}
impl Eq for Shell {}