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