From 5357d0dd6dbfbb545ee7ddc41ea4527775ca2e4b Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Wed, 8 Jan 2020 10:07:56 -0800 Subject: Use symbolic default values where possible With the switch to using structopt for argument parsing some of the default values have become mere strings, whereas one of our earlier objectives was to have symbolic values where that is possible. As structopt works with symbolic values equally well, this change makes it use those. As a bonus, also list the possible formats for the --format option to the otp set subcommand. --- src/args.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/args.rs b/src/args.rs index 5c6ad4c..aeedfe6 100644 --- a/src/args.rs +++ b/src/args.rs @@ -287,7 +287,8 @@ Command! {OtpCommand, [ #[derive(Debug, PartialEq, structopt::StructOpt)] struct OtpClearArgs { /// The OTP algorithm to use - #[structopt(short, long, default_value = "totp", possible_values = &OtpAlgorithm::all_str())] + #[structopt(short, long, default_value = OtpAlgorithm::Totp.as_ref(), + possible_values = &OtpAlgorithm::all_str())] algorithm: OtpAlgorithm, /// The OTP slot to clear slot: u8, @@ -296,7 +297,8 @@ struct OtpClearArgs { #[derive(Debug, PartialEq, structopt::StructOpt)] struct OtpGetArgs { /// The OTP algorithm to use - #[structopt(short, long, default_value = "totp", possible_values = &OtpAlgorithm::all_str())] + #[structopt(short, long, default_value = OtpAlgorithm::Totp.as_ref(), + possible_values = &OtpAlgorithm::all_str())] algorithm: OtpAlgorithm, /// The time to use for TOTP generation (Unix timestamp) [default: system time] #[structopt(short, long)] @@ -308,10 +310,12 @@ struct OtpGetArgs { #[derive(Debug, PartialEq, structopt::StructOpt)] struct OtpSetArgs { /// The OTP algorithm to use - #[structopt(short, long, default_value = "totp", possible_values = &OtpAlgorithm::all_str())] + #[structopt(short, long, default_value = OtpAlgorithm::Totp.as_ref(), + possible_values = &OtpAlgorithm::all_str())] algorithm: OtpAlgorithm, /// The number of digits to use for the one-time password - #[structopt(short, long, default_value = "6", possible_values = &OtpMode::all_str())] + #[structopt(short, long, default_value = OtpMode::SixDigits.as_ref(), + possible_values = &OtpMode::all_str())] digits: OtpMode, /// The counter value for HOTP #[structopt(short, long, default_value = "0")] @@ -320,7 +324,8 @@ struct OtpSetArgs { #[structopt(short, long, default_value = "30")] time_window: u16, /// The format of the secret - #[structopt(short, long, default_value = "hex")] + #[structopt(short, long, default_value = OtpSecretFormat::Hex.as_ref(), + possible_values = &OtpSecretFormat::all_str())] format: OtpSecretFormat, /// The OTP slot to use slot: u8, -- cgit v1.2.3