soroban_cli/commands/network/
default.rs

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