mod auth_cmd;
mod chain_cmd;
mod config_cmd;
mod f3_cmd;
mod healthcheck_cmd;
mod info_cmd;
mod mpool_cmd;
mod net_cmd;
mod shutdown_cmd;
mod snapshot_cmd;
mod state_cmd;
mod sync_cmd;
mod wait_api_cmd;
pub(super) use self::{
auth_cmd::AuthCommands, chain_cmd::ChainCommands, config_cmd::ConfigCommands,
f3_cmd::F3Commands, healthcheck_cmd::HealthcheckCommand, mpool_cmd::MpoolCommands,
net_cmd::NetCommands, shutdown_cmd::ShutdownCommand, snapshot_cmd::SnapshotCommands,
state_cmd::StateCommands, sync_cmd::SyncCommands, wait_api_cmd::WaitApiCommand,
};
use crate::cli::subcommands::info_cmd::InfoCommand;
pub(crate) use crate::cli_shared::cli::Config;
use crate::cli_shared::cli::HELP_MESSAGE;
use crate::lotus_json::HasLotusJson;
use crate::utils::version::FOREST_VERSION_STRING;
use clap::Parser;
use spire_enum::prelude::delegated_enum;
use tracing::error;
#[derive(Parser)]
#[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")
)]
#[command(help_template(HELP_MESSAGE))]
pub struct Cli {
#[arg(short, long)]
pub token: Option<String>,
#[command(subcommand)]
pub cmd: Subcommand,
}
#[delegated_enum]
#[derive(clap::Subcommand, Debug)]
pub enum Subcommand {
#[command(subcommand)]
Chain(ChainCommands),
#[command(subcommand)]
Auth(AuthCommands),
#[command(subcommand)]
Net(NetCommands),
#[command(subcommand)]
Sync(SyncCommands),
#[command(subcommand)]
Mpool(MpoolCommands),
#[command(subcommand)]
State(StateCommands),
#[command(subcommand)]
Config(ConfigCommands),
#[command(subcommand)]
Snapshot(SnapshotCommands),
#[command(subcommand)]
Info(InfoCommand),
Shutdown(ShutdownCommand),
#[command(subcommand)]
Healthcheck(HealthcheckCommand),
#[command(subcommand)]
F3(F3Commands),
WaitApi(WaitApiCommand),
}
impl Subcommand {
pub async fn run(self, client: crate::rpc::Client) -> anyhow::Result<()> {
delegate_subcommand!(self.run(client).await)
}
}
pub fn cli_error_and_die(msg: impl AsRef<str>, code: i32) -> ! {
error!("Error: {}", msg.as_ref());
std::process::exit(code);
}
pub(super) fn print_pretty_lotus_json<T: HasLotusJson>(obj: T) -> anyhow::Result<()> {
println!("{}", obj.into_lotus_json_string_pretty()?);
Ok(())
}
pub(super) fn print_rpc_res_bytes(obj: Vec<u8>) -> anyhow::Result<()> {
println!("{}", String::from_utf8(obj)?);
Ok(())
}
pub fn prompt_confirm() -> bool {
let term = dialoguer::console::Term::stderr();
if !term.is_term() {
return false;
}
dialoguer::Confirm::new()
.with_prompt("Do you want to continue?")
.interact_on(&term)
.unwrap_or(false)
}