Compare commits

..

No commits in common. "3567865c2da0c994fbaa549dd4346640db3f4bf7" and "90bcf968d423d7bcf3e6937cd6d0c0afecad9bbd" have entirely different histories.

2 changed files with 9 additions and 33 deletions

View file

@ -55,10 +55,6 @@ custom fields.
For secrets like the password and TOTP secret, you can provide them as arguments For secrets like the password and TOTP secret, you can provide them as arguments
or you will be prompted for them. or you will be prompted for them.
## Field removal
If you want to remove a field from the vault, you can provide an empty value for
it, e.g. `-o ""`.
## Custom fields ## Custom fields
If you want to add a custom field to the vault, you can use the `-c, --custom` If you want to add a custom field to the vault, you can use the `-c, --custom`
option, and provide the key-value pair. If you want to delete a custom field, option, and provide the key-value pair. If you want to delete a custom field,

View file

@ -82,43 +82,23 @@ impl LprsCommand for Edit {
if let Some(new_name) = self.name { if let Some(new_name) = self.name {
vault.name = new_name; vault.name = new_name;
} }
if let Some(ref new_password) = self.password { if self.password.is_some() {
if new_password.as_deref().is_some_and(|s| s.is_empty()) { vault.password = utils::user_secret(self.password, "New vault password:", false)?;
vault.password = None;
} else {
vault.password = utils::user_secret(self.password, "New vault password:", false)?;
}
} }
if let Some(totp_secret) = utils::user_secret(self.totp_secret, "TOTP Secret:", false)? { if let Some(totp_secret) = utils::user_secret(self.totp_secret, "TOTP Secret:", false)? {
if totp_secret.is_empty() { cipher::base32_decode(&totp_secret).map_err(|_| {
vault.totp_secret = None; LprsError::Base32("Invalid TOTP secret, must be valid base32 string".to_owned())
} else { })?;
cipher::base32_decode(&totp_secret).map_err(|_| { vault.totp_secret = Some(totp_secret);
LprsError::Base32("Invalid TOTP secret, must be valid base32 string".to_owned())
})?;
vault.totp_secret = Some(totp_secret);
}
} }
if let Some(new_username) = self.username { if let Some(new_username) = self.username {
if new_username.is_empty() { vault.username = Some(new_username);
vault.username = None;
} else {
vault.username = Some(new_username);
}
} }
if let Some(new_service) = self.service { if let Some(new_service) = self.service {
if new_service.is_empty() { vault.service = Some(new_service);
vault.service = None;
} else {
vault.service = Some(new_service);
}
} }
if let Some(new_note) = self.note { if let Some(new_note) = self.note {
if new_note.is_empty() { vault.note = Some(new_note);
vault.note = None;
} else {
vault.note = Some(new_note);
}
} }
utils::apply_custom_fields(&mut vault.custom_fields, self.custom_fields); utils::apply_custom_fields(&mut vault.custom_fields, self.custom_fields);