Skip to content

Commit

Permalink
Provide correct mutual exclusion between config set -o and -O options
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
d-e-s-o committed Jan 25, 2020
1 parent 8640118 commit 61b5aff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
17 changes: 17 additions & 0 deletions src/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 61b5aff

Please sign in to comment.