From 61b5aff7be250387ce8510138cae773ed3bd6577 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Fri, 24 Jan 2020 20:36:34 -0800 Subject: 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. --- src/tests/config.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/tests') diff --git a/src/tests/config.rs b/src/tests/config.rs index 728fdbd..fa311d5 100644 --- a/src/tests/config.rs +++ b/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( -- cgit v1.2.3