From e09f5d841dd05ca2f1d276ba678ccbc02d0207e5 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Sun, 13 Oct 2019 04:07:07 -0700 Subject: Properly show the default format used in otp set subcommand The otp set subcommand allows for three different formats in which the user may pass in the secret, with the default being hexadecimal. By convention we convey the default being used in the help text to the respective command, but that default was missing here. To that end, this change makes sure to include the default format being used in corresponding help text. --- nitrocli/src/args.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/nitrocli/src/args.rs b/nitrocli/src/args.rs index fe35a9e..9f4cae2 100644 --- a/nitrocli/src/args.rs +++ b/nitrocli/src/args.rs @@ -624,10 +624,11 @@ pub fn otp_set(ctx: &mut ExecCtx<'_>, args: Vec) -> Result<()> { let mut digits = OtpMode::SixDigits; let mut counter: u64 = 0; let mut time_window: u16 = 30; - let mut secret_format: Option = None; + let mut secret_format = OtpSecretFormat::Hex; let fmt_help = format!( - "The format of the secret ({})", - fmt_enum!(OtpSecretFormat::all_variants()) + "The format of the secret ({}, default: {})", + fmt_enum!(OtpSecretFormat::all_variants()), + secret_format, ); let mut parser = argparse::ArgumentParser::new(); parser.set_description("Configures a one-time password slot"); @@ -665,15 +666,12 @@ pub fn otp_set(ctx: &mut ExecCtx<'_>, args: Vec) -> Result<()> { argparse::Store, "The time window for TOTP (default: 30)", ); - let _ = parser.refer(&mut secret_format).add_option( - &["-f", "--format"], - argparse::StoreOption, - &fmt_help, - ); + let _ = + parser + .refer(&mut secret_format) + .add_option(&["-f", "--format"], argparse::Store, &fmt_help); parse(ctx, parser, args)?; - let secret_format = secret_format.unwrap_or(OtpSecretFormat::Hex); - let data = nitrokey::OtpSlotData { number: slot, name, -- cgit v1.2.1