aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2020-01-08 10:07:56 -0800
committerDaniel Mueller <deso@posteo.net>2020-01-08 10:07:56 -0800
commitc5b73d50b5c3d6de81e1003d698d57e157a6400f (patch)
treef913991f48fb8b29b86cb07cfb520f95cab5dd22
parentc0d8583e0aba69b0628eb9c036f50a86f33d381f (diff)
downloadnitrocli-c5b73d50b5c3d6de81e1003d698d57e157a6400f.tar.gz
nitrocli-c5b73d50b5c3d6de81e1003d698d57e157a6400f.tar.bz2
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.
-rw-r--r--nitrocli/src/args.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/nitrocli/src/args.rs b/nitrocli/src/args.rs
index 0ca17a5..8ff03be 100644
--- a/nitrocli/src/args.rs
+++ b/nitrocli/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,