aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2020-01-24 20:36:34 -0800
committerDaniel Mueller <deso@posteo.net>2020-01-24 20:36:34 -0800
commit5a781ef0f2276436fa90dd3097817d06a9510c9a (patch)
tree33bfe33e24b421286c09b92bc2d8055b2be68545
parent1e86d7f71f3cf4809b9a443b72bea3f9656e1b1b (diff)
downloadnitrocli-5a781ef0f2276436fa90dd3097817d06a9510c9a.tar.gz
nitrocli-5a781ef0f2276436fa90dd3097817d06a9510c9a.tar.bz2
Provide correct mutual exclusion between config set -o and -O options
The -o/--otp-pin and -O/--no-otp-pin options to the config set command are supposed to be mutually exclusive, with wrong usage detected by structopt. That is not the case currently, however, because the argument to structopt's conflicts_with attribute is supposed to be the resulting option and not the name of the variable capturing the result. This change fixes the problem by changing the string accordingly.
-rw-r--r--nitrocli/src/args.rs2
-rw-r--r--nitrocli/src/tests/config.rs17
2 files changed, 18 insertions, 1 deletions
diff --git a/nitrocli/src/args.rs b/nitrocli/src/args.rs
index 91bddc5..57e9743 100644
--- a/nitrocli/src/args.rs
+++ b/nitrocli/src/args.rs
@@ -172,7 +172,7 @@ struct ConfigSetArgs {
#[structopt(short = "o", long)]
otp_pin: bool,
/// Allows one-time password generation without PIN
- #[structopt(short = "O", long, conflicts_with("otp_pin"))]
+ #[structopt(short = "O", long, conflicts_with("otp-pin"))]
no_otp_pin: bool,
}
diff --git a/nitrocli/src/tests/config.rs b/nitrocli/src/tests/config.rs
index 728fdbd..fa311d5 100644
--- a/nitrocli/src/tests/config.rs
+++ b/nitrocli/src/tests/config.rs
@@ -19,6 +19,23 @@
use super::*;
+#[test]
+fn mutually_exclusive_set_options() {
+ fn test(option1: &str, option2: &str) {
+ let (rc, out, err) = Nitrocli::new().run(&["config", "set", option1, option2]);
+
+ assert_ne!(rc, 0);
+ assert_eq!(out, b"");
+
+ let err = String::from_utf8(err).unwrap();
+ assert!(err.contains("cannot be used with"), err);
+ }
+
+ test("-c", "-C");
+ test("-o", "-O");
+ test("-s", "-S");
+}
+
#[test_device]
fn get(model: nitrokey::Model) -> crate::Result<()> {
let re = regex::Regex::new(