From d4eae4d631c02f155ff58109cb79a49f62b028ab Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 26 Apr 2021 17:26:10 +1200 Subject: [PATCH] Add name field to TUI Closes str4d/age-plugin-yubikey#28. --- src/main.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 20fd5e8..2f8e310 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use age_plugin::run_state_machine; -use dialoguer::{Confirm, Select}; +use dialoguer::{Confirm, Input, Select}; use gumdrop::Options; use yubikey_piv::{ certificate::PublicKeyInfo, @@ -385,6 +385,18 @@ fn main() -> Result<(), Error> { return Ok(()); } } else { + let name = match Input::::new() + .with_prompt(format!( + "📛 Name this identity [{}]", + opts.name.as_deref().unwrap_or("age identity TAG_HEX") + )) + .allow_empty(true) + .interact_text()? + { + s if s.is_empty() => opts.name, + s => Some(s), + }; + let pin_policy = match Select::new() .with_prompt("🔤 Select a PIN policy") .items(&[ @@ -425,7 +437,7 @@ fn main() -> Result<(), Error> { { eprintln!(); builder::IdentityBuilder::new(Some(slot)) - .with_name(opts.name) + .with_name(name) .with_pin_policy(Some(pin_policy)) .with_touch_policy(Some(touch_policy)) .force(opts.force)