forest/cli/subcommands/
mod.rs1mod auth_cmd;
10mod chain_cmd;
11mod config_cmd;
12mod f3_cmd;
13mod healthcheck_cmd;
14mod index_cmd;
15mod info_cmd;
16mod mpool_cmd;
17mod net_cmd;
18mod shutdown_cmd;
19mod snapshot_cmd;
20mod state_cmd;
21mod sync_cmd;
22mod wait_api_cmd;
23
24pub(super) use self::{
25 auth_cmd::AuthCommands, chain_cmd::ChainCommands, config_cmd::ConfigCommands,
26 f3_cmd::F3Commands, healthcheck_cmd::HealthcheckCommand, index_cmd::IndexCommands,
27 mpool_cmd::MpoolCommands, net_cmd::NetCommands, shutdown_cmd::ShutdownCommand,
28 snapshot_cmd::SnapshotCommands, state_cmd::StateCommands, sync_cmd::SyncCommands,
29 wait_api_cmd::WaitApiCommand,
30};
31use crate::cli::subcommands::info_cmd::InfoCommand;
32pub(crate) use crate::cli_shared::cli::Config;
33use crate::cli_shared::cli::HELP_MESSAGE;
34use crate::lotus_json::HasLotusJson;
35use crate::utils::version::FOREST_VERSION_STRING;
36use clap::Parser;
37use spire_enum::prelude::delegated_enum;
38use tracing::error;
39
40#[derive(Parser)]
42#[command(name = env!("CARGO_PKG_NAME"), bin_name = "forest-cli", author = env!("CARGO_PKG_AUTHORS"), version = FOREST_VERSION_STRING.as_str(), about = env!("CARGO_PKG_DESCRIPTION")
43)]
44#[command(help_template(HELP_MESSAGE))]
45pub struct Cli {
46 #[arg(short, long)]
48 pub token: Option<String>,
49 #[command(subcommand)]
50 pub cmd: Subcommand,
51}
52
53#[delegated_enum]
55#[derive(clap::Subcommand, Debug)]
56pub enum Subcommand {
57 #[command(subcommand)]
59 Chain(ChainCommands),
60
61 #[command(subcommand)]
63 Auth(AuthCommands),
64
65 #[command(subcommand)]
67 Net(NetCommands),
68
69 #[command(subcommand)]
71 Sync(SyncCommands),
72
73 #[command(subcommand)]
75 Mpool(MpoolCommands),
76
77 #[command(subcommand)]
79 State(StateCommands),
80
81 #[command(subcommand)]
83 Config(ConfigCommands),
84
85 #[command(subcommand)]
87 Snapshot(SnapshotCommands),
88
89 #[command(subcommand)]
91 Index(IndexCommands),
92
93 #[command(subcommand)]
95 Info(InfoCommand),
96
97 Shutdown(ShutdownCommand),
99
100 #[command(subcommand)]
102 Healthcheck(HealthcheckCommand),
103
104 #[command(subcommand)]
106 F3(F3Commands),
107
108 WaitApi(WaitApiCommand),
110}
111
112impl Subcommand {
113 pub async fn run(self, client: crate::rpc::Client) -> anyhow::Result<()> {
114 delegate_subcommand!(self.run(client).await)
115 }
116}
117
118pub fn cli_error_and_die(msg: impl AsRef<str>, code: i32) -> ! {
121 error!("Error: {}", msg.as_ref());
122 std::process::exit(code);
123}
124
125pub(super) fn print_pretty_lotus_json<T: HasLotusJson>(obj: T) -> anyhow::Result<()> {
127 println!("{}", obj.into_lotus_json_string_pretty()?);
128 Ok(())
129}
130
131pub(super) fn print_rpc_res_bytes(obj: Vec<u8>) -> anyhow::Result<()> {
133 println!("{}", String::from_utf8(obj)?);
134 Ok(())
135}
136
137pub fn prompt_confirm() -> bool {
139 let term = dialoguer::console::Term::stderr();
140
141 if !term.is_term() {
142 return false;
143 }
144
145 dialoguer::Confirm::new()
146 .with_prompt("Do you want to continue?")
147 .interact_on(&term)
148 .unwrap_or(false)
149}