diff --git a/src/inputs.rs b/src/inputs.rs index acbe331f4beb21cd7c414001858ca7b06ef61548..e430312798847ec6861a4c829b962054c56a774c 100644 --- a/src/inputs.rs +++ b/src/inputs.rs @@ -24,9 +24,9 @@ pub fn prompt_password_query_confirm(query: impl ToString) -> Result<String, Gcl /// Prompt for a (direct) vault name (cannot contain derivation path) /// -/// Also preventing to use '<' and '>' as those are used in the display of +/// Also preventing to use '<' and '>' as those are used in the display pub fn prompt_vault_name() -> Result<Option<String>, GcliError> { - inquire::Text::new("Name:") + let name = inquire::Text::new("Name:") .with_validator(|input: &str| { if input.contains('<') || input.contains('>') || input.contains('/') { Ok(Validation::Invalid( @@ -36,8 +36,14 @@ pub fn prompt_vault_name() -> Result<Option<String>, GcliError> { Ok(Validation::Valid) } }) - .prompt_skippable() - .map_err(|e| GcliError::Input(e.to_string())) + .prompt() + .map_err(|e| GcliError::Input(e.to_string()))?; + + Ok(if name.trim().is_empty() { + None + } else { + Some(name.trim().to_string()) + }) } /// Prompt for a derivation path