feat(cli): relicario settings show / trash-retention / history-retention / attachment-cap
This commit is contained in:
@@ -1201,7 +1201,48 @@ fn cmd_generate(length: u32, bip39: bool, words: u32, symbols: String, separator
|
||||
println!("{}", output.as_str());
|
||||
Ok(())
|
||||
}
|
||||
fn cmd_settings(_a: SettingsAction) -> Result<()> { bail!("not yet implemented"); }
|
||||
fn cmd_settings(action: SettingsAction) -> Result<()> {
|
||||
use relicario_core::{HistoryRetention, TrashRetention};
|
||||
|
||||
let vault = crate::session::UnlockedVault::unlock_interactive()?;
|
||||
let mut settings = vault.load_settings()?;
|
||||
|
||||
match action {
|
||||
SettingsAction::Show => {
|
||||
println!("{}", serde_json::to_string_pretty(&settings)?);
|
||||
return Ok(());
|
||||
}
|
||||
SettingsAction::TrashRetention { days, forever } => {
|
||||
settings.trash_retention = match (days, forever) {
|
||||
(Some(d), false) => TrashRetention::Days(d),
|
||||
(None, true) => TrashRetention::Forever,
|
||||
_ => anyhow::bail!("specify exactly one of --days or --forever"),
|
||||
};
|
||||
}
|
||||
SettingsAction::HistoryRetention { last_n, days, forever } => {
|
||||
settings.field_history_retention = match (last_n, days, forever) {
|
||||
(Some(n), None, false) => HistoryRetention::LastN(n),
|
||||
(None, Some(d), false) => HistoryRetention::Days(d),
|
||||
(None, None, true) => HistoryRetention::Forever,
|
||||
_ => anyhow::bail!("specify exactly one of --last-n / --days / --forever"),
|
||||
};
|
||||
}
|
||||
SettingsAction::AttachmentCap {
|
||||
per_attachment_max_bytes, per_item_max_count,
|
||||
per_vault_soft_cap_bytes, per_vault_hard_cap_bytes,
|
||||
} => {
|
||||
if let Some(v) = per_attachment_max_bytes { settings.attachment_caps.per_attachment_max_bytes = v; }
|
||||
if let Some(v) = per_item_max_count { settings.attachment_caps.per_item_max_count = v; }
|
||||
if let Some(v) = per_vault_soft_cap_bytes { settings.attachment_caps.per_vault_soft_cap_bytes = v; }
|
||||
if let Some(v) = per_vault_hard_cap_bytes { settings.attachment_caps.per_vault_hard_cap_bytes = v; }
|
||||
}
|
||||
}
|
||||
|
||||
vault.save_settings(&settings)?;
|
||||
commit_paths(&vault, "settings: update", &["settings.enc"])?;
|
||||
eprintln!("Settings updated.");
|
||||
Ok(())
|
||||
}
|
||||
fn cmd_sync() -> Result<()> { bail!("not yet implemented"); }
|
||||
fn cmd_device(_a: DeviceAction) -> Result<()> { bail!("not yet implemented"); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user