From 223ec22b5741d969800230188e4af7a4a0d1e98e Mon Sep 17 00:00:00 2001 From: Nicolas80 <nicolas.pmail@protonmail.com> Date: Wed, 15 Jan 2025 16:36:52 +0100 Subject: [PATCH] Small cleanup for `vault use` command and saving Config --- src/commands/vault.rs | 14 ++++++++------ src/conf.rs | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/commands/vault.rs b/src/commands/vault.rs index adf9245..8c8fc31 100644 --- a/src/commands/vault.rs +++ b/src/commands/vault.rs @@ -169,13 +169,15 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE } => { let derivation = retrieve_vault_derivation(&data, address_or_vault_name).await?; - //FIXME not sure if this is ok (but since it's a CLI; this data instance won't be used afterwards) - let mut data = data; - data.cfg.address = - Some(AccountId::from_str(&derivation.address).expect("invalid address")); - println!("Using: {}", derivation); - conf::save_config(&data); + + let updated_cfg = conf::Config { + address: Some(AccountId::from_str(&derivation.address).expect("invalid address")), + ..data.cfg + }; + + //This updated configuration will be picked up with next GCli execution + conf::save(&updated_cfg); } Subcommand::Generate => { // TODO allow custom word count diff --git a/src/conf.rs b/src/conf.rs index 95f5279..207e7c6 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -96,7 +96,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE } } Subcommand::Save => { - save_config(&data); + save(&data.cfg); } Subcommand::Default => { confy::store(APP_NAME, None, Config::default()).expect("unable to write config"); @@ -106,7 +106,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE Ok(()) } -pub fn save_config(data: &Data) { - confy::store(APP_NAME, None, &data.cfg).expect("unable to write config"); +pub fn save(cfg: &Config) { + confy::store(APP_NAME, None, cfg).expect("unable to write config"); println!("Configuration updated!"); } -- GitLab