aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2022-08-20 19:43:35 +0200
committerTeddy Wing2022-08-20 19:43:35 +0200
commit13b24a39bf855584541892b2406562c2dc8fcc2b (patch)
tree16252dd7d9deb5e04bfe296b24af17b69983d725
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.
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs15
3 files changed, 21 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 57aaf77..ddb95b6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
]
diff --git a/Cargo.toml b/Cargo.toml
index 368b968..58bf90f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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 {
"-"