Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion clap-v3-utils/src/keygen/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,32 @@ pub const NO_PASSPHRASE_ARG: ArgConstant<'static> = ArgConstant {
help: "Do not prompt for a BIP39 passphrase",
};

// The constant `POSSIBLE_WORD_COUNTS` and function `try_get_word_count` must always be updated in
// sync
const POSSIBLE_WORD_COUNTS: &[&str] = &["12", "15", "18", "21", "24"];
pub fn word_count_arg<'a>() -> Arg<'a> {
Arg::new(WORD_COUNT_ARG.name)
.long(WORD_COUNT_ARG.long)
.value_parser(PossibleValuesParser::new(["12", "15", "18", "21", "24"]))
.value_parser(PossibleValuesParser::new(POSSIBLE_WORD_COUNTS))
.default_value("12")
.value_name("NUMBER")
.takes_value(true)
.help(WORD_COUNT_ARG.help)
}

pub fn try_get_word_count(matches: &ArgMatches) -> Result<Option<usize>, Box<dyn error::Error>> {
Ok(matches
.try_get_one::<String>(WORD_COUNT_ARG.name)?
.map(|count| match count.as_str() {
"12" => 12,
"15" => 15,
"18" => 18,
"21" => 21,
"24" => 24,
_ => unreachable!(),
}))
}

pub fn language_arg<'a>() -> Arg<'a> {
Arg::new(LANGUAGE_ARG.name)
.long(LANGUAGE_ARG.long)
Expand Down