soroban_cli/commands/network/
mod.rs1use 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(add::Cmd),
16
17 Rm(rm::Cmd),
19
20 Ls(ls::Cmd),
22
23 #[cfg(feature = "version_lt_23")]
35 Start(crate::commands::container::StartCmd),
36
37 #[cfg(feature = "version_lt_23")]
41 Stop(crate::commands::container::StopCmd),
42
43 #[command(name = "use")]
47 Default(default::Cmd),
48
49 #[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}