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