keyfork mnemonic generate: impl ValueEnum for SeedSize

This commit is contained in:
Ryan Heywood 2023-10-19 12:08:16 -05:00
parent 5d5d5181b3
commit 64c5c648a6
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
1 changed files with 15 additions and 1 deletions

View File

@ -1,5 +1,5 @@
use super::Keyfork;
use clap::{Parser, Subcommand, ValueEnum};
use clap::{Parser, Subcommand, ValueEnum, builder::PossibleValue};
use std::fmt::Display;
#[derive(Clone, Debug, Default)]
@ -10,6 +10,20 @@ pub enum SeedSize {
Bits256,
}
// custom impl to override names in ValueEnum
impl ValueEnum for SeedSize {
fn value_variants<'a>() -> &'a [Self] {
&[Self::Bits128, Self::Bits256]
}
fn to_possible_value(&self) -> Option<PossibleValue> {
Some(PossibleValue::new(match self {
SeedSize::Bits128 => "128",
SeedSize::Bits256 => "256",
}))
}
}
#[derive(thiserror::Error, Debug, Clone)]
pub enum SeedSizeError {
#[error("Expected one of 128, 256")]