From 64c5c648a6f30bca0c31a5f2abf0117ba20f315b Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 19 Oct 2023 12:08:16 -0500 Subject: [PATCH] keyfork mnemonic generate: impl ValueEnum for SeedSize --- keyfork/src/cli/mnemonic.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/keyfork/src/cli/mnemonic.rs b/keyfork/src/cli/mnemonic.rs index 2fa9b88..685e3a2 100644 --- a/keyfork/src/cli/mnemonic.rs +++ b/keyfork/src/cli/mnemonic.rs @@ -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 { + 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")]