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