soroban_cli/commands/network/
mod.rs

1use clap::Parser;
2
3use crate::rpc::{self};
4
5use super::{config::locator, global};
6
7pub mod add;
8pub mod default;
9pub mod ls;
10pub mod rm;
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
57#[derive(thiserror::Error, Debug)]
58pub enum Error {
59    #[error(transparent)]
60    Default(#[from] default::Error),
61
62    #[error(transparent)]
63    Add(#[from] add::Error),
64
65    #[error(transparent)]
66    Rm(#[from] rm::Error),
67
68    #[error(transparent)]
69    Ls(#[from] ls::Error),
70
71    #[cfg(feature = "version_lt_23")]
72    #[error(transparent)]
73    Start(#[from] crate::commands::container::start::Error),
74
75    #[cfg(feature = "version_lt_23")]
76    #[error(transparent)]
77    Stop(#[from] crate::commands::container::stop::Error),
78
79    #[cfg(feature = "version_lt_23")]
80    #[error(transparent)]
81    Container(#[from] crate::commands::container::Error),
82
83    #[error(transparent)]
84    Config(#[from] locator::Error),
85
86    #[error("network arg or rpc url and network passphrase are required if using the network")]
87    Network,
88    #[error(transparent)]
89    Rpc(#[from] rpc::Error),
90    #[error(transparent)]
91    HttpClient(#[from] reqwest::Error),
92    #[error("Failed to parse JSON from {0}, {1}")]
93    FailedToParseJSON(String, serde_json::Error),
94    #[error("Invalid URL {0}")]
95    InvalidUrl(String),
96    #[error("Inproper response {0}")]
97    InproperResponse(String),
98}
99
100impl Cmd {
101    pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
102        match self {
103            Cmd::Default(cmd) => cmd.run(global_args)?,
104            Cmd::Add(cmd) => cmd.run()?,
105            Cmd::Rm(new) => new.run()?,
106            Cmd::Ls(cmd) => cmd.run()?,
107            #[cfg(feature = "version_lt_23")]
108            Cmd::Container(cmd) => cmd.run(global_args).await?,
109
110            #[cfg(feature = "version_lt_23")]
111            Cmd::Start(cmd) => {
112                eprintln!("⚠️ Warning: `network start` has been deprecated. Use `container start` instead");
113                cmd.run(global_args).await?;
114            }
115            #[cfg(feature = "version_lt_23")]
116            Cmd::Stop(cmd) => {
117                println!(
118                    "⚠️ Warning: `network stop` has been deprecated. Use `container stop` instead"
119                );
120                cmd.run(global_args).await?;
121            }
122        };
123        Ok(())
124    }
125}