From 5d1398832c6651e57aaaad64bad96e9d7796d3f4 Mon Sep 17 00:00:00 2001 From: Awiteb Date: Tue, 7 May 2024 20:25:45 +0300 Subject: [PATCH] chore: Pass the prompt message as an argument to the user_password function --- src/cli/add_command.rs | 2 +- src/cli/edit_command.rs | 2 +- src/utils.rs | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cli/add_command.rs b/src/cli/add_command.rs index 29d986a..a14686a 100644 --- a/src/cli/add_command.rs +++ b/src/cli/add_command.rs @@ -38,7 +38,7 @@ pub struct Add { impl LprsCommand for Add { fn run(mut self, mut vault_manager: Vaults) -> LprsResult<()> { - self.vault_info.password = utils::user_password(self.password)?; + self.vault_info.password = utils::user_password(self.password, "Vault password:")?; vault_manager.add_vault(self.vault_info); vault_manager.try_export() } diff --git a/src/cli/edit_command.rs b/src/cli/edit_command.rs index aefae0c..2069d82 100644 --- a/src/cli/edit_command.rs +++ b/src/cli/edit_command.rs @@ -68,7 +68,7 @@ impl LprsCommand for Edit { *vault = Vault::new( self.name.as_ref().unwrap_or(&vault.name), self.username.as_ref().or(vault.username.as_ref()), - utils::user_password(self.password)? + utils::user_password(self.password, "New vault password:")? .as_ref() .or(vault.password.as_ref()), self.service.as_ref().or(vault.service.as_ref()), diff --git a/src/utils.rs b/src/utils.rs index a9210fd..525b0ce 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -52,14 +52,17 @@ pub fn local_project_file(filename: &str) -> LprsResult { /// /// ## Errors /// - When failed to get the password from stdin -pub fn user_password(password: Option>) -> LprsResult> { +pub fn user_password( + password: Option>, + prompt_message: &str, +) -> LprsResult> { Ok(match password { None => None, Some(Some(p)) => Some(p), Some(None) => { log::debug!("User didn't provide a password, prompting it"); Some( - Password::new("Vault password:") + Password::new(prompt_message) .without_confirmation() .with_formatter(&|p| "*".repeat(p.chars().count())) .with_display_mode(PasswordDisplayMode::Masked)