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 settings;
11
12#[derive(Debug, Parser)]
13pub enum Cmd {
14    /// Add a new network
15    Add(add::Cmd),
16
17    /// Remove a network
18    Rm(rm::Cmd),
19
20    /// List networks
21    Ls(ls::Cmd),
22
23    /// Set the default network that will be used on all commands.
24    /// This allows you to skip `--network` or setting a environment variable,
25    /// while reusing this value in all commands that require it.
26    #[command(name = "use")]
27    Default(default::Cmd),
28
29    /// Fetch the health of the configured RPC
30    Health(health::Cmd),
31
32    /// Checks the health of the configured RPC
33    Info(info::Cmd),
34
35    /// Fetch the network's config settings
36    Settings(settings::Cmd),
37}
38
39#[derive(thiserror::Error, Debug)]
40pub enum Error {
41    #[error(transparent)]
42    Default(#[from] default::Error),
43
44    #[error(transparent)]
45    Add(#[from] add::Error),
46
47    #[error(transparent)]
48    Rm(#[from] rm::Error),
49
50    #[error(transparent)]
51    Ls(#[from] ls::Error),
52
53    #[error(transparent)]
54    Health(#[from] health::Error),
55
56    #[error(transparent)]
57    Info(#[from] info::Error),
58
59    #[error(transparent)]
60    Settings(#[from] settings::Error),
61}
62
63impl Cmd {
64    pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
65        match self {
66            Cmd::Default(cmd) => cmd.run(global_args)?,
67            Cmd::Add(cmd) => cmd.run()?,
68            Cmd::Rm(new) => new.run()?,
69            Cmd::Ls(cmd) => cmd.run()?,
70            Cmd::Health(cmd) => cmd.run(global_args).await?,
71            Cmd::Info(cmd) => cmd.run(global_args).await?,
72            Cmd::Settings(cmd) => cmd.run(global_args).await?,
73        }
74        Ok(())
75    }
76}