From b619f78f45fdd3ecbcaa2e30134866e8ab694d6d Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 29 Sep 2020 19:18:56 +0200 Subject: Rename numlock, capslock, scrollock options This patch renames the options for the config set command: --numlock ==> --num-lock --capslock ==> --caps-lock --scrolllock ==> --scroll-lock --no-numlock ==> --no-num-lock --no-capslock ==> --no-caps-lock --no-scrolllock ==> --no-scroll-lock The original naming was based on a typo in nitrokey-rs (scrollock vs. scrolllock). Also, the typical spelling for the keys is Num Lock, Caps Lock and Scroll Lock, so using a hyphen is a more natural. --- src/args.rs | 30 +++++++++++++++--------------- src/commands.rs | 25 +++++++++++++------------ src/tests/config.rs | 16 ++++++++-------- 3 files changed, 36 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/args.rs b/src/args.rs index a38ca6a..6cf37c8 100644 --- a/src/args.rs +++ b/src/args.rs @@ -125,24 +125,24 @@ Command! {ConfigCommand, [ #[derive(Debug, PartialEq, structopt::StructOpt)] pub struct ConfigSetArgs { - /// Sets the numlock option to the given HOTP slot + /// Sets the Num Lock option to the given HOTP slot #[structopt(short = "n", long)] - pub numlock: Option, - /// Unsets the numlock option - #[structopt(short = "N", long, conflicts_with("numlock"))] - pub no_numlock: bool, - /// Sets the capslock option to the given HOTP slot + pub num_lock: Option, + /// Unsets the Num Lock option + #[structopt(short = "N", long, conflicts_with("num-lock"))] + pub no_num_lock: bool, + /// Sets the Cap Lock option to the given HOTP slot #[structopt(short = "c", long)] - pub capslock: Option, - /// Unsets the capslock option - #[structopt(short = "C", long, conflicts_with("capslock"))] - pub no_capslock: bool, - /// Sets the scrollock option to the given HOTP slot + pub caps_lock: Option, + /// Unsets the Caps Lock option + #[structopt(short = "C", long, conflicts_with("caps-lock"))] + pub no_caps_lock: bool, + /// Sets the Scroll Lock option to the given HOTP slot #[structopt(short = "s", long)] - pub scrollock: Option, - /// Unsets the scrollock option - #[structopt(short = "S", long, conflicts_with("scrollock"))] - pub no_scrollock: bool, + pub scroll_lock: Option, + /// Unsets the Scroll Lock option + #[structopt(short = "S", long, conflicts_with("scroll-lock"))] + pub no_scroll_lock: bool, /// Requires the user PIN to generate one-time passwords #[structopt(short = "o", long)] pub otp_pin: bool, diff --git a/src/commands.rs b/src/commands.rs index eba9276..092b006 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -657,9 +657,9 @@ pub fn config_get(ctx: &mut Context<'_>) -> anyhow::Result<()> { println!( ctx, r#"Config: - numlock binding: {nl} - capslock binding: {cl} - scrollock binding: {sl} + num lock binding: {nl} + caps lock binding: {cl} + scroll lock binding: {sl} require user PIN for OTP: {otp}"#, nl = format_option(config.num_lock), cl = format_option(config.caps_lock), @@ -672,12 +672,13 @@ pub fn config_get(ctx: &mut Context<'_>) -> anyhow::Result<()> { /// Write the Nitrokey configuration. pub fn config_set(ctx: &mut Context<'_>, args: args::ConfigSetArgs) -> anyhow::Result<()> { - let numlock = args::ConfigOption::try_from(args.no_numlock, args.numlock, "numlock") - .context("Failed to apply numlock configuration")?; - let capslock = args::ConfigOption::try_from(args.no_capslock, args.capslock, "capslock") - .context("Failed to apply capslock configuration")?; - let scrollock = args::ConfigOption::try_from(args.no_scrollock, args.scrollock, "scrollock") - .context("Failed to apply scrollock configuration")?; + let num_lock = args::ConfigOption::try_from(args.no_num_lock, args.num_lock, "numlock") + .context("Failed to apply num lock configuration")?; + let caps_lock = args::ConfigOption::try_from(args.no_caps_lock, args.caps_lock, "capslock") + .context("Failed to apply caps lock configuration")?; + let scroll_lock = + args::ConfigOption::try_from(args.no_scroll_lock, args.scroll_lock, "scrollock") + .context("Failed to apply scroll lock configuration")?; let otp_pin = if args.otp_pin { Some(true) } else if args.no_otp_pin { @@ -692,9 +693,9 @@ pub fn config_set(ctx: &mut Context<'_>, args: args::ConfigSetArgs) -> anyhow::R .get_config() .context("Failed to get current configuration")?; let config = nitrokey::Config { - num_lock: numlock.or(config.num_lock), - caps_lock: capslock.or(config.caps_lock), - scroll_lock: scrollock.or(config.scroll_lock), + num_lock: num_lock.or(config.num_lock), + caps_lock: caps_lock.or(config.caps_lock), + scroll_lock: scroll_lock.or(config.scroll_lock), user_password: otp_pin.unwrap_or(config.user_password), }; device diff --git a/src/tests/config.rs b/src/tests/config.rs index babd32c..b3d27de 100644 --- a/src/tests/config.rs +++ b/src/tests/config.rs @@ -26,9 +26,9 @@ fn mutually_exclusive_set_options() { fn get(model: nitrokey::Model) -> anyhow::Result<()> { let re = regex::Regex::new( r#"^Config: - numlock binding: (not set|\d+) - capslock binding: (not set|\d+) - scrollock binding: (not set|\d+) + num lock binding: (not set|\d+) + caps lock binding: (not set|\d+) + scroll lock binding: (not set|\d+) require user PIN for OTP: (true|false) $"#, ) @@ -44,12 +44,12 @@ $"#, fn set_wrong_usage(model: nitrokey::Model) { let err = Nitrocli::new() .model(model) - .handle(&["config", "set", "--numlock", "2", "-N"]) + .handle(&["config", "set", "--num-lock", "2", "-N"]) .unwrap_err() .to_string(); assert!( - err.contains("The argument '--numlock ' cannot be used with '--no-numlock'"), + err.contains("The argument '--num-lock ' cannot be used with '--no-num-lock'"), err, ); } @@ -61,9 +61,9 @@ fn set_get(model: nitrokey::Model) -> anyhow::Result<()> { let re = regex::Regex::new( r#"^Config: - numlock binding: not set - capslock binding: 0 - scrollock binding: 1 + num lock binding: not set + caps lock binding: 0 + scroll lock binding: 1 require user PIN for OTP: (true|false) $"#, ) -- cgit v1.2.3