blob: 90e33b77aa529afba38f3b1d499866de9dfa7ac0 (
plain) (
blame)
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
|
use clap;
use colors;
pub struct CommandLineOptions {
pub shell: colors::ShellType,
pub error_code: u8,
}
pub fn parse() -> CommandLineOptions {
let matches = clap::App::new("fancy-prompt")
.about("Prints a fancy prompt")
.author(crate_authors!())
.version(crate_version!())
.arg(clap::Arg::with_name("prompt-escape")
.long("prompt-escape")
.value_name("SHELL")
.help("Produces escape sequence wrappers for the given shell")
.takes_value(true))
.arg(clap::Arg::with_name("error-code")
.value_name("ERROR_CODE")
.help("The error code of the previously run command")
)
.get_matches();
let shell = matches
.value_of("prompt-escape")
.map(|shell| colors::ShellType::from_str(shell))
.unwrap_or(colors::ShellType::Unknown);
let error_code = matches
.value_of("error-code")
.map(|code| code.parse().expect("error code must be a u8"))
.unwrap_or(0);
CommandLineOptions {
shell,
error_code,
}
}
|