Add name field to TUI

Closes str4d/age-plugin-yubikey#28.
This commit is contained in:
Jack Grigg
2021-04-26 17:26:10 +12:00
parent 64b0ab4e16
commit d4eae4d631
+14 -2
View File
@@ -1,5 +1,5 @@
use age_plugin::run_state_machine; use age_plugin::run_state_machine;
use dialoguer::{Confirm, Select}; use dialoguer::{Confirm, Input, Select};
use gumdrop::Options; use gumdrop::Options;
use yubikey_piv::{ use yubikey_piv::{
certificate::PublicKeyInfo, certificate::PublicKeyInfo,
@@ -385,6 +385,18 @@ fn main() -> Result<(), Error> {
return Ok(()); return Ok(());
} }
} else { } else {
let name = match Input::<String>::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() let pin_policy = match Select::new()
.with_prompt("🔤 Select a PIN policy") .with_prompt("🔤 Select a PIN policy")
.items(&[ .items(&[
@@ -425,7 +437,7 @@ fn main() -> Result<(), Error> {
{ {
eprintln!(); eprintln!();
builder::IdentityBuilder::new(Some(slot)) builder::IdentityBuilder::new(Some(slot))
.with_name(opts.name) .with_name(name)
.with_pin_policy(Some(pin_policy)) .with_pin_policy(Some(pin_policy))
.with_touch_policy(Some(touch_policy)) .with_touch_policy(Some(touch_policy))
.force(opts.force) .force(opts.force)