diff options
| author | Teddy Wing | 2022-08-20 19:43:35 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2022-08-20 19:43:35 +0200 | 
| commit | 13b24a39bf855584541892b2406562c2dc8fcc2b (patch) | |
| tree | 16252dd7d9deb5e04bfe296b24af17b69983d725 | |
| parent | 4dfe6642eafff6638dc09c673eb1ac727d1438d9 (diff) | |
| download | Passextract-13b24a39bf855584541892b2406562c2dc8fcc2b.tar.bz2 | |
Add version command line argument
* -V and --version now print the program version and exit
* Use the `exitcode` crate
* Rename `options` variable to `accepted_args`, which seems clearer
  given its usage.
| -rw-r--r-- | Cargo.lock | 7 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/main.rs | 15 | 
3 files changed, 21 insertions, 2 deletions
| @@ -34,6 +34,12 @@ dependencies = [  ]  [[package]] +name = "exitcode" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de853764b47027c2e862a995c34978ffa63c1501f2e15f987ba11bd4f9bba193" + +[[package]]  name = "gag"  version = "0.1.9"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -102,6 +108,7 @@ name = "passextract"  version = "0.5.0"  dependencies = [   "clipboard", + "exitcode",   "rustty",  ] @@ -4,4 +4,5 @@ version = "0.5.0"  [dependencies]  clipboard = "0.1.2" +exitcode = "1.1.2"  rustty = "0.1" diff --git a/src/main.rs b/src/main.rs index fbbd252..38a6d3b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@  // file for more information.  extern crate clipboard; +extern crate exitcode;  extern crate rustty;  use clipboard::ClipboardContext; @@ -114,7 +115,17 @@ fn main() {      // TODO: Add --version -V arg      // TODO: When done, update man page -    let options = ["-i"]; +    let accepted_args = ["-i", "-V", "--version"]; + +    match args.get(1) { +        Some(arg) => { +            if arg == "-V" || arg == "--version" { +                println!("{}", env!("CARGO_PKG_VERSION")); +                process::exit(exitcode::OK); +            } +        } +        None => (), +    }      let hide_password = match args.get(1) {          Some(arg) if arg == "-i" => true, @@ -124,7 +135,7 @@ fn main() {      let last_arg = &args[args.len() - 1];      let input = if args.len() > 1 && -            !options.contains(&last_arg.as_ref()) { +            !accepted_args.contains(&last_arg.as_ref()) {          last_arg      } else {          "-" | 
