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