aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/args.rs30
-rw-r--r--src/commands.rs25
-rw-r--r--src/tests/config.rs16
3 files changed, 36 insertions, 35 deletions
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<u8>,
- /// 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<u8>,
+ /// 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<u8>,
- /// 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<u8>,
+ /// 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<u8>,
- /// Unsets the scrollock option
- #[structopt(short = "S", long, conflicts_with("scrollock"))]
- pub no_scrollock: bool,
+ pub scroll_lock: Option<u8>,
+ /// 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 <numlock>' cannot be used with '--no-numlock'"),
+ err.contains("The argument '--num-lock <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)
$"#,
)