soroban_cli/commands/contract/alias/
remove.rs1use std::fmt::Debug;
2
3use clap::Parser;
4
5use crate::commands::{config::network, global};
6use crate::config::{address::AliasName, alias, locator};
7use crate::print::Print;
8
9#[derive(Parser, Debug, Clone)]
10#[group(skip)]
11pub struct Cmd {
12 #[command(flatten)]
13 pub config_locator: locator::Args,
14
15 #[command(flatten)]
16 network: network::Args,
17
18 pub alias: AliasName,
20}
21
22#[derive(thiserror::Error, Debug)]
23pub enum Error {
24 #[error(transparent)]
25 Locator(#[from] locator::Error),
26
27 #[error(transparent)]
28 Network(#[from] network::Error),
29
30 #[error("no contract found with alias '{alias}' for network '{network_passphrase}'")]
31 NoContract {
32 alias: String,
33 network_passphrase: String,
34 },
35}
36
37impl Cmd {
38 pub fn run(&self, global_args: &global::Args) -> Result<(), Error> {
39 let print = Print::new(global_args.quiet);
40 let alias = &self.alias;
41 let network = self.network.get(&self.config_locator)?;
42 let network_passphrase = &network.network_passphrase;
43
44 let Some(contract) = self
47 .config_locator
48 .get_stored_contract_id(&self.alias, network_passphrase)?
49 else {
50 if alias::is_reserved(&self.alias) {
55 return Err(locator::Error::ContractAliasReserved(self.alias.to_string()).into());
56 }
57
58 return Err(Error::NoContract {
59 alias: alias.to_string(),
60 network_passphrase: network_passphrase.into(),
61 });
62 };
63
64 print.infoln(format!(
65 "Contract alias '{alias}' references {contract} on network '{network_passphrase}'"
66 ));
67
68 self.config_locator
69 .remove_contract_id(&network.network_passphrase, alias)?;
70
71 print.checkln(format!("Contract alias '{alias}' has been removed"));
72
73 Ok(())
74 }
75}