From 8451f2c710bce47a048252d75a9d30f92943b381 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Mon, 6 Jan 2020 20:07:44 -0500 Subject: [PATCH 1/4] Use updated gumdrop so we can print the default help to stdout with no args or flags --- Cargo.lock | 20 +++++++++----------- Cargo.toml | 2 +- src/bin/rage/main.rs | 5 ++++- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ee691a8c..ddbe1d13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,7 +62,9 @@ dependencies = [ "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", "fuse_mt 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gumdrop 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "gumdrop 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "hkdf 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", @@ -562,20 +564,18 @@ dependencies = [ [[package]] name = "gumdrop" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +version = "0.7.0" dependencies = [ - "gumdrop_derive 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "gumdrop_derive 0.7.0", ] [[package]] name = "gumdrop_derive" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +version = "0.7.0" dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1650,8 +1650,6 @@ dependencies = [ "checksum fuse_mt 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e63cd7846849c0edf7c8655b3e952848117b2670fa8054ea2fc123040577414b" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" -"checksum gumdrop 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a57b4113bb9af093a1cd0b505a44a93103e32e258296d01fa2def3f37c2c7cc" -"checksum gumdrop_derive 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dae5488e2c090f7586e2027e4ea6fcf8c9d83e2ef64d623993a33a0fb811f1f7" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum hermit-abi 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f629dc602392d3ec14bfc8a09b5e644d7ffd725102b48b81e59f90f2633621d7" "checksum hkdf 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fa08a006102488bd9cd5b8013aabe84955cf5ae22e304c2caf655b633aefae3" diff --git a/Cargo.toml b/Cargo.toml index a93f5fe4..0e67ea0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -92,7 +92,7 @@ zeroize = "1" # Common CLI dependencies dialoguer = { version = "0.4", optional = true } dirs = { version = "2", optional = true } -gumdrop = { version = "0.6", optional = true } +gumdrop = { version = "0.7", optional = true } log = { version = "0.4", optional = true } # rage and rage-keygen dependencies diff --git a/src/bin/rage/main.rs b/src/bin/rage/main.rs index 130f9d6b..dbc69cfe 100644 --- a/src/bin/rage/main.rs +++ b/src/bin/rage/main.rs @@ -314,7 +314,10 @@ fn main() -> Result<(), error::Error> { if opts.decrypt { decrypt(opts).map_err(error::Error::from) - } else { + } else if opts.recipient.len() > 0 { encrypt(opts).map_err(error::Error::from) + } else { + AgeOptions::print_usage(opts); + Ok(()) } } From 422c1c6793c21c48859e94598918937b2f576000 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Tue, 7 Jan 2020 17:30:51 -0500 Subject: [PATCH 2/4] Reverting Cargo.lock changes --- Cargo.lock | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ddbe1d13..ee691a8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,9 +62,7 @@ dependencies = [ "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", "fuse_mt 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", - "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "gumdrop 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "gumdrop 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "hkdf 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", @@ -564,18 +562,20 @@ dependencies = [ [[package]] name = "gumdrop" -version = "0.7.0" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gumdrop_derive 0.7.0", + "gumdrop_derive 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "gumdrop_derive" -version = "0.7.0" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1650,6 +1650,8 @@ dependencies = [ "checksum fuse_mt 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e63cd7846849c0edf7c8655b3e952848117b2670fa8054ea2fc123040577414b" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" +"checksum gumdrop 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a57b4113bb9af093a1cd0b505a44a93103e32e258296d01fa2def3f37c2c7cc" +"checksum gumdrop_derive 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dae5488e2c090f7586e2027e4ea6fcf8c9d83e2ef64d623993a33a0fb811f1f7" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum hermit-abi 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f629dc602392d3ec14bfc8a09b5e644d7ffd725102b48b81e59f90f2633621d7" "checksum hkdf 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fa08a006102488bd9cd5b8013aabe84955cf5ae22e304c2caf655b633aefae3" From c7e4fda5c5009b7dcbcfb9feac57174ac0311c76 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Tue, 7 Jan 2020 17:31:27 -0500 Subject: [PATCH 3/4] Display standard help dialog if TTY and the only arg is the command name itself --- src/bin/rage/main.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/bin/rage/main.rs b/src/bin/rage/main.rs index dbc69cfe..a6fdb9d4 100644 --- a/src/bin/rage/main.rs +++ b/src/bin/rage/main.rs @@ -308,16 +308,29 @@ fn decrypt(opts: AgeOptions) -> Result<(), error::DecryptError> { } fn main() -> Result<(), error::Error> { + use std::env::args; + env_logger::builder().format_timestamp(None).init(); + let args = args().collect::>(); + + // If you are piping input with no other args, this will not allow + // it. + if console::user_attended() && args.len() == 1 { + // If gumdrop ever merges that PR, that can be used here + // instead. + println!("Usage: {} [OPTIONS]", args[0]); + println!(); + println!("{}", AgeOptions::usage()); + + return Ok(()); + } + let opts = AgeOptions::parse_args_default_or_exit(); if opts.decrypt { decrypt(opts).map_err(error::Error::from) - } else if opts.recipient.len() > 0 { - encrypt(opts).map_err(error::Error::from) } else { - AgeOptions::print_usage(opts); - Ok(()) + encrypt(opts).map_err(error::Error::from) } } From c305e8505ee363fea4afd97408f44d59bdfaceae Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Tue, 7 Jan 2020 17:58:46 -0500 Subject: [PATCH 4/4] Revert gumdrop version bump --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0e67ea0a..a93f5fe4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -92,7 +92,7 @@ zeroize = "1" # Common CLI dependencies dialoguer = { version = "0.4", optional = true } dirs = { version = "2", optional = true } -gumdrop = { version = "0.7", optional = true } +gumdrop = { version = "0.6", optional = true } log = { version = "0.4", optional = true } # rage and rage-keygen dependencies