Skip to content

Commit

Permalink
fix: validate digits input value from command line
Browse files Browse the repository at this point in the history
  • Loading branch information
replydev committed Jun 19, 2024
1 parent 95cf5a2 commit d03d4b8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/arguments/add.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::Args;
use clap::{value_parser, Args};
use color_eyre::eyre::{eyre, ErrReport};

use zeroize::Zeroize;
Expand Down Expand Up @@ -39,7 +39,8 @@ pub struct AddArgs {
short,
long,
default_value_t = 6,
default_value_if("type", "STEAM", "5")
default_value_if("type", "STEAM", "5"),
value_parser=value_parser!(u64).range(0..=9)
)]
pub digits: u64,

Expand Down
4 changes: 2 additions & 2 deletions src/arguments/edit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::Args;
use clap::{value_parser, Args};
use color_eyre::eyre::eyre;

use crate::otp::{otp_algorithm::OTPAlgorithm, otp_element::OTPDatabase};
Expand All @@ -24,7 +24,7 @@ pub struct EditArgs {
pub algorithm: Option<OTPAlgorithm>,

/// Code digits
#[arg(short, long)]
#[arg(short, long, value_parser=value_parser!(u64).range(0..=9))]
pub digits: Option<u64>,

/// Code period
Expand Down

0 comments on commit d03d4b8

Please sign in to comment.