soroban_cli/commands/contract/alias/
show.rs1use std::fmt::Debug;
2
3use clap::{command, Parser};
4
5use crate::commands::{config::network, global};
6use crate::config::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: String,
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 if let Some(contract) = self
45 .config_locator
46 .get_contract_id(&self.alias, network_passphrase)?
47 {
48 print.infoln(format!(
49 "Contract alias '{alias}' references {contract} on network '{network_passphrase}'"
50 ));
51
52 println!("{contract}");
53
54 Ok(())
55 } else {
56 Err(Error::NoContract {
57 alias: alias.into(),
58 network_passphrase: network_passphrase.into(),
59 })
60 }
61 }
62}