From 134846769b2ba27dbbf951bb11bb45f410789868 Mon Sep 17 00:00:00 2001 From: Nando Vieira Date: Fri, 14 Jun 2024 09:38:33 -0700 Subject: [PATCH] Remove guard from function and bring it to the caller. --- cmd/soroban-cli/src/commands/config/alias.rs | 8 ++------ cmd/soroban-cli/src/commands/contract/deploy/wasm.rs | 5 +++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/cmd/soroban-cli/src/commands/config/alias.rs b/cmd/soroban-cli/src/commands/config/alias.rs index f2436bc72..ca17c411e 100644 --- a/cmd/soroban-cli/src/commands/config/alias.rs +++ b/cmd/soroban-cli/src/commands/config/alias.rs @@ -32,7 +32,7 @@ pub enum Error { } impl Args { - pub fn load(&self, alias: &str) -> Result, Error> { + fn load(&self, alias: &str) -> Result, Error> { let path = self.alias_path(alias)?; if !path.exists() { @@ -51,11 +51,7 @@ impl Args { Ok(config_dir.join("contract-ids").join(file_name)) } - pub fn save_contract_id(&self, contract_id: &str, alias: Option<&String>) -> Result<(), Error> { - let Some(alias) = alias else { - return Ok(()); - }; - + pub fn save_contract_id(&self, contract_id: &str, alias: &str) -> Result<(), Error> { let path = self.alias_path(alias)?; let dir = path.parent().ok_or(Error::CannotAccessConfigDir)?; diff --git a/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs b/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs index 989a594a6..2f85268b4 100644 --- a/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs +++ b/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs @@ -120,8 +120,9 @@ impl Cmd { match res { TxnEnvelopeResult::TxnEnvelope(tx) => println!("{}", tx.to_xdr_base64(Limits::none())?), TxnEnvelopeResult::Res(contract) => { - self.config - .save_contract_id(&contract, self.alias.as_ref())?; + if let Some(alias) = self.alias.clone() { + self.config.save_contract_id(&contract, &alias)?; + } println!("{contract}"); }