Skip to main content

soroban_cli/commands/network/
mod.rs

1use super::{config::locator, global};
2use clap::Parser;
3
4pub mod add;
5pub mod default;
6pub mod health;
7pub mod info;
8pub mod ls;
9pub mod rm;
10pub mod root_account;
11pub mod settings;
12pub mod unset;
13
14#[derive(Debug, Parser)]
15pub enum Cmd {
16    /// Add a new network
17    Add(add::Cmd),
18
19    /// Remove a network
20    Rm(rm::Cmd),
21
22    /// List networks
23    Ls(ls::Cmd),
24
25    /// Set the default network that will be used on all commands.
26    /// This allows you to skip `--network` or setting a environment variable,
27    /// while reusing this value in all commands that require it.
28    #[command(name = "use")]
29    Default(default::Cmd),
30
31    /// Fetch the health of the configured RPC
32    Health(health::Cmd),
33
34    /// Checks the health of the configured RPC
35    Info(info::Cmd),
36
37    /// Fetch the network's config settings
38    Settings(settings::Cmd),
39
40    /// Unset the default network defined previously with `network use <network>`
41    Unset(unset::Cmd),
42
43    /// Compute the root account keypair for a network.
44    #[command(subcommand)]
45    RootAccount(root_account::Cmd),
46}
47
48#[derive(thiserror::Error, Debug)]
49pub enum Error {
50    #[error(transparent)]
51    Default(#[from] default::Error),
52
53    #[error(transparent)]
54    Add(#[from] add::Error),
55
56    #[error(transparent)]
57    Rm(#[from] rm::Error),
58
59    #[error(transparent)]
60    Ls(#[from] ls::Error),
61
62    #[error(transparent)]
63    Health(#[from] health::Error),
64
65    #[error(transparent)]
66    Info(#[from] info::Error),
67
68    #[error(transparent)]
69    Settings(#[from] settings::Error),
70
71    #[error(transparent)]
72    Unset(#[from] unset::Error),
73
74    #[error(transparent)]
75    RootAccount(#[from] root_account::Error),
76}
77
78impl Cmd {
79    pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
80        match self {
81            Cmd::Default(cmd) => cmd.run(global_args)?,
82            Cmd::Add(cmd) => cmd.run()?,
83            Cmd::Rm(new) => new.run()?,
84            Cmd::Ls(cmd) => cmd.run()?,
85            Cmd::Health(cmd) => cmd.run(global_args).await?,
86            Cmd::Info(cmd) => cmd.run(global_args).await?,
87            Cmd::Settings(cmd) => cmd.run(global_args).await?,
88            Cmd::Unset(cmd) => cmd.run(global_args)?,
89            Cmd::RootAccount(cmd) => cmd.run(global_args)?,
90        }
91        Ok(())
92    }
93}