aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-03-14 16:08:33 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-03-14 16:08:33 +0100
commite21b2fddd58cacb4dbd99699c2bd83cb5bf2a349 (patch)
tree7724895ebb13e781eb40250d0e98b4a3af147067
parenta696c1e949b3c3906737bf74bd552dec2cc35eb7 (diff)
downloadcheckpw-e21b2fddd58cacb4dbd99699c2bd83cb5bf2a349.tar.gz
checkpw-e21b2fddd58cacb4dbd99699c2bd83cb5bf2a349.tar.bz2
checkpw-e21b2fddd58cacb4dbd99699c2bd83cb5bf2a349.zip
Print usage if no args or passwords given.
-rw-r--r--src/main.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 9e18a85..b742d95 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -110,11 +110,20 @@ fn check(pw: Password) -> Result<(), Box<::std::error::Error>> {
Ok(())
}
+fn print_usage() {
+ println!("Usage: checkpw <pw>...");
+}
+
fn main() {
- let (_args, passwords) : (Vec<String>, Vec<String>) = env::args()
+ let (args, passwords) : (Vec<String>, Vec<String>) = env::args()
.skip(1)
.partition(|arg| arg.starts_with('-'));
+ if args.is_empty() && passwords.is_empty() {
+ print_usage();
+ return;
+ }
+
for pw in passwords {
check(Password::new(&pw)).unwrap();
}