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    /// ⚠️ Deprecated: use `stellar container start` instead
24    ///
25    /// Start network
26    ///
27    /// Start a container running a Stellar node, RPC, API, and friendbot (faucet).
28    ///
29    /// `stellar network start NETWORK [OPTIONS]`
30    ///
31    /// By default, when starting a testnet container, without any optional arguments, it will run the equivalent of the following docker command:
32    ///
33    /// `docker run --rm -p 8000:8000 --name stellar stellar/quickstart:testing --testnet --enable rpc,horizon`
34    #[cfg(feature = "version_lt_23")]
35    Start(crate::commands::container::StartCmd),
36
37    /// ⚠️ Deprecated: use `stellar container stop` instead
38    ///
39    /// Stop a network started with `network start`. For example, if you ran `stellar network start local`, you can use `stellar network stop local` to stop it.
40    #[cfg(feature = "version_lt_23")]
41    Stop(crate::commands::container::StopCmd),
42
43    /// Set the default network that will be used on all commands.
44    /// This allows you to skip `--network` or setting a environment variable,
45    /// while reusing this value in all commands that require it.
46    #[command(name = "use")]
47    Default(default::Cmd),
48
49    /// ⚠️ Deprecated: use `stellar container` instead
50    ///
51    /// Commands to start, stop and get logs for a quickstart container
52    #[cfg(feature = "version_lt_23")]
53    #[command(subcommand)]
54    Container(crate::commands::container::Cmd),
55
56    /// Fetch the health of the configured RPC
57    Health(health::Cmd),
58
59    /// Checks the health of the configured RPC
60    Info(info::Cmd),
61
62    /// Fetch the network's config settings
63    Settings(settings::Cmd),
64}
65
66#[derive(thiserror::Error, Debug)]
67pub enum Error {
68    #[error(transparent)]
69    Default(#[from] default::Error),
70
71    #[error(transparent)]
72    Add(#[from] add::Error),
73
74    #[error(transparent)]
75    Rm(#[from] rm::Error),
76
77    #[error(transparent)]
78    Ls(#[from] ls::Error),
79
80    #[error(transparent)]
81    Health(#[from] health::Error),
82
83    #[error(transparent)]
84    Info(#[from] info::Error),
85
86    #[error(transparent)]
87    Settings(#[from] settings::Error),
88
89    #[cfg(feature = "version_lt_23")]
90    #[error(transparent)]
91    Start(#[from] crate::commands::container::start::Error),
92
93    #[cfg(feature = "version_lt_23")]
94    #[error(transparent)]
95    Stop(#[from] crate::commands::container::stop::Error),
96
97    #[cfg(feature = "version_lt_23")]
98    #[error(transparent)]
99    Container(#[from] crate::commands::container::Error),
100}
101
102impl Cmd {
103    pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
104        match self {
105            Cmd::Default(cmd) => cmd.run(global_args)?,
106            Cmd::Add(cmd) => cmd.run()?,
107            Cmd::Rm(new) => new.run()?,
108            Cmd::Ls(cmd) => cmd.run()?,
109            #[cfg(feature = "version_lt_23")]
110            Cmd::Container(cmd) => cmd.run(global_args).await?,
111
112            #[cfg(feature = "version_lt_23")]
113            Cmd::Start(cmd) => {
114                eprintln!("⚠️ Warning: `network start` has been deprecated. Use `container start` instead");
115                cmd.run(global_args).await?;
116            }
117            #[cfg(feature = "version_lt_23")]
118            Cmd::Stop(cmd) => {
119                println!(
120                    "⚠️ Warning: `network stop` has been deprecated. Use `container stop` instead"
121                );
122                cmd.run(global_args).await?;
123            }
124            Cmd::Health(cmd) => cmd.run(global_args).await?,
125            Cmd::Info(cmd) => cmd.run(global_args).await?,
126            Cmd::Settings(cmd) => cmd.run(global_args).await?,
127        }
128        Ok(())
129    }
130}