soroban_cli/commands/keys/
default.rs

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