From 84df513ac4c7bc93bfedc98dacd3b9e8d1358fa7 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 2 Jun 2016 17:19:10 -0400 Subject: fix arg handling error messages; make nonces and keys optional (if no-crypto) --- src/client.rs | 18 ++++++++++++++---- src/main.rs | 2 +- src/server.rs | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/client.rs b/src/client.rs index 6aa48ce..b7aeb74 100644 --- a/src/client.rs +++ b/src/client.rs @@ -105,15 +105,15 @@ pub fn main_client() { opts.optopt("t", "to", "file or dir to write to (client side)", "FILE"); opts.reqopt("", "host", "remote hostname to connect to", "HOSTNAME"); opts.reqopt("", "port", "remote port to connect to", "PORT"); - opts.reqopt("", "read-nonce", "secret read nonce", "NONCE"); - opts.reqopt("", "write-nonce", "secret write nonce", "NONCE"); - opts.reqopt("", "key", "secret key", "NONCE"); + opts.optopt("", "read-nonce", "secret read nonce", "NONCE"); + opts.optopt("", "write-nonce", "secret write nonce", "NONCE"); + opts.optopt("", "key", "secret key", "NONCE"); opts.optflag("", "no-crypto", "sends data in the clear (no crypto or verification)"); assert!(args.len() >= 2 && args[1] == "client"); let matches = match opts.parse(&args[2..]) { Ok(m) => { m } - Err(f) => { println!("Error parsing args!"); usage_client(opts); exit(-1); } + Err(f) => { println!("{}", f.to_string()); usage_client(opts); exit(-1); } }; if matches.opt_present("h") { @@ -125,6 +125,16 @@ pub fn main_client() { let dir_mode: bool = matches.opt_present("d"); let no_crypto: bool = matches.opt_present("no-crypto"); + if !no_crypto { + if !matches.opt_present("key") || + !matches.opt_present("read-nonce") || + !matches.opt_present("write-nonce") { + println!("If not --no-crypto, --key and --read-nonce and --write-nonce are required."); + usage_client(opts); + exit(-1); + } + } + match (matches.opt_present("f"), matches.opt_present("t")) { (true, true) | (false, false) => { println!("Must be either 'from' or 'to', but not both"); diff --git a/src/main.rs b/src/main.rs index 6eb7de5..1077034 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,7 +46,7 @@ fn main() { let matches = match opts.parse(&args[1..]) { Ok(m) => { m } - Err(f) => { println!("Error parsing args: {}", f); usage(opts); exit(-1); } + Err(f) => { println!("{}", f.to_string()); usage(opts); exit(-1); } }; //let verbose: bool = matches.opt_present("v"); diff --git a/src/server.rs b/src/server.rs index 3288867..66dfc69 100644 --- a/src/server.rs +++ b/src/server.rs @@ -117,7 +117,7 @@ pub fn main_server() { assert!(args.len() >= 2 && args[1] == "server"); let matches = match opts.parse(&args[2..]) { Ok(m) => { m } - Err(f) => { println!("Error parsing args!"); usage_server(opts); exit(-1); } + Err(f) => { println!("{}", f.to_string()); usage_server(opts); exit(-1); } }; if matches.opt_present("h") { -- cgit v1.2.3