aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2018-03-01 23:58:25 +0100
committerTeddy Wing2018-03-01 23:58:25 +0100
commit9faef460fa13857ca26b4447b9d627bb76e9bbd9 (patch)
tree338a6c27dd5267b3a4ce7307c73f606856322019 /src
parentf43eafeab711ea4be4a71c732228b1244466e9b4 (diff)
downloadPassextract-9faef460fa13857ca26b4447b9d627bb76e9bbd9.tar.bz2
Clean up condition for getting file path from argument
Instead of the convoluted hard-to-read `hide_password &&` nonsense, give ourselves a way to express the condition in terms of the argument _not_ being one of our accepted options (only `-i`). This ensures that we either capture the filename in the last argument or use STDIN.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 69f7736..7411c1a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -92,15 +92,18 @@ fn is_password_line(line: &str) -> bool {
fn main() {
let args: Vec<String> = env::args().collect();
+ let options = ["-i"];
+
let hide_password = match args.get(1) {
Some(arg) if arg == "-i" => true,
Some(_) => false,
None => false,
};
- let input = if hide_password && args.len() > 2 ||
- !hide_password && args.len() > 1 {
- &args[args.len() - 1]
+ let last_arg = &args[args.len() - 1];
+ let input = if args.len() > 1 &&
+ !options.contains(&last_arg.as_ref()) {
+ last_arg
} else {
"-"
};