aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorTeddy Wing2022-08-20 19:43:35 +0200
committerTeddy Wing2022-08-20 19:43:35 +0200
commit13b24a39bf855584541892b2406562c2dc8fcc2b (patch)
tree16252dd7d9deb5e04bfe296b24af17b69983d725 /src/main.rs
parent4dfe6642eafff6638dc09c673eb1ac727d1438d9 (diff)
downloadPassextract-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.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs15
1 files changed, 13 insertions, 2 deletions
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 {
"-"