Skip to content

Commit

Permalink
Properly show the default format used in otp set subcommand
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
d-e-s-o committed Oct 13, 2019
1 parent 4d57ac6 commit e09f5d8
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions nitrocli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,10 +624,11 @@ pub fn otp_set(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
let mut digits = OtpMode::SixDigits;
let mut counter: u64 = 0;
let mut time_window: u16 = 30;
let mut secret_format: Option<OtpSecretFormat> = 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");
Expand Down Expand Up @@ -665,15 +666,12 @@ pub fn otp_set(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> 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,
Expand Down

0 comments on commit e09f5d8

Please sign in to comment.