soroban_cli/commands/network/
default.rs

1use crate::{commands::global, print::Print};
2
3use super::locator;
4
5#[derive(thiserror::Error, Debug)]
6pub enum Error {
7    #[error(transparent)]
8    Config(#[from] locator::Error),
9}
10
11#[derive(Debug, clap::Parser, Clone)]
12#[group(skip)]
13pub struct Cmd {
14    /// Set the default network name.
15    pub name: String,
16
17    #[command(flatten)]
18    pub config_locator: locator::Args,
19}
20
21impl Cmd {
22    pub fn run(&self, global_args: &global::Args) -> Result<(), Error> {
23        let printer = Print::new(global_args.quiet);
24
25        if std::env::var("STELLAR_NETWORK").is_ok()
26            && std::env::var("STELLAR_NETWORK_SOURCE").is_err()
27        {
28            printer.warnln("Environment variable STELLAR_NETWORK is set, which will override this default network.");
29        }
30
31        let _ = self.config_locator.read_network(&self.name)?;
32        self.config_locator.write_default_network(&self.name)?;
33
34        printer.infoln(format!("The default network is set to `{}`", self.name));
35
36        Ok(())
37    }
38}