diff options
author | Jesse Luehrs <doy@tozt.net> | 2018-05-14 16:26:14 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2018-05-14 16:26:14 -0400 |
commit | f49066fc12bb8766492491daba84e1c068ab5e15 (patch) | |
tree | ab09f8ea7fa81434cf21fe5a1b640e4b4a6044a9 /src/args.rs | |
parent | 3e4cd71073fb3b30792aaf1443261e966cbbcf4b (diff) | |
download | fancy-prompt-f49066fc12bb8766492491daba84e1c068ab5e15.tar.gz fancy-prompt-f49066fc12bb8766492491daba84e1c068ab5e15.zip |
reorganize a bit
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/args.rs b/src/args.rs new file mode 100644 index 0000000..90e33b7 --- /dev/null +++ b/src/args.rs @@ -0,0 +1,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, + } +} + |