diff --git a/tools/src/bin/opgpcard/cli.rs b/tools/src/bin/opgpcard/cli.rs index ea348e7..43a3d71 100644 --- a/tools/src/bin/opgpcard/cli.rs +++ b/tools/src/bin/opgpcard/cli.rs @@ -146,8 +146,8 @@ pub enum Command { #[clap(name = "card ident", short = 'c', long = "card")] ident: String, - #[clap(name = "identity")] - id: u8, + #[clap(name = "identity", value_enum)] + id: SetIdentityId, }, } @@ -358,3 +358,23 @@ impl From for openpgp_card_sequoia::types::TouchPolicy { } } } + +#[derive(ValueEnum, Debug, Clone)] +pub enum SetIdentityId { + #[clap(name = "0")] + Zero, + #[clap(name = "1")] + One, + #[clap(name = "2")] + Two, +} + +impl From for u8 { + fn from(id: SetIdentityId) -> Self { + match id { + SetIdentityId::Zero => 0, + SetIdentityId::One => 1, + SetIdentityId::Two => 2, + } + } +} diff --git a/tools/src/bin/opgpcard/main.rs b/tools/src/bin/opgpcard/main.rs index 84cd541..09d1809 100644 --- a/tools/src/bin/opgpcard/main.rs +++ b/tools/src/bin/opgpcard/main.rs @@ -579,13 +579,12 @@ fn list_cards(format: OutputFormat, output_version: OutputVersion) -> Result<()> Ok(()) } -fn set_identity(ident: &str, id: u8) -> Result<(), Box> { +fn set_identity(ident: &str, id: cli::SetIdentityId) -> Result<(), Box> { let backend = util::open_card(ident)?; let mut card = Card::new(backend); let mut open = card.transaction()?; - open.set_identity(id)?; - + open.set_identity(u8::from(id))?; Ok(()) }