chore: Pass the prompt message as an argument to the user_password function

This commit is contained in:
Awiteb 2024-05-07 20:25:45 +03:00
parent 914222976c
commit 5d1398832c
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F
3 changed files with 7 additions and 4 deletions

View file

@ -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()
}

View file

@ -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()),

View file

@ -52,14 +52,17 @@ pub fn local_project_file(filename: &str) -> LprsResult<PathBuf> {
///
/// ## Errors
/// - When failed to get the password from stdin
pub fn user_password(password: Option<Option<String>>) -> LprsResult<Option<String>> {
pub fn user_password(
password: Option<Option<String>>,
prompt_message: &str,
) -> LprsResult<Option<String>> {
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)