mod auth_cmd;
mod chain_cmd;
mod config_cmd;
mod healthcheck_cmd;
mod info_cmd;
mod mpool_cmd;
mod net_cmd;
pub(crate) mod send_cmd;
mod shutdown_cmd;
mod snapshot_cmd;
mod state_cmd;
mod sync_cmd;
use std::io::Write;
pub(crate) use crate::cli_shared::cli::Config;
use crate::cli_shared::cli::HELP_MESSAGE;
use crate::utils::version::FOREST_VERSION_STRING;
use crate::{blocks::Tipset, lotus_json::HasLotusJson};
use clap::Parser;
use tracing::error;
pub(super) use self::{
auth_cmd::AuthCommands, chain_cmd::ChainCommands, config_cmd::ConfigCommands,
healthcheck_cmd::HealthcheckCommand, mpool_cmd::MpoolCommands, net_cmd::NetCommands,
send_cmd::SendCommand, shutdown_cmd::ShutdownCommand, snapshot_cmd::SnapshotCommands,
state_cmd::StateCommands, sync_cmd::SyncCommands,
};
use crate::cli::subcommands::info_cmd::InfoCommand;
#[derive(Parser)]
#[command(name = env!("CARGO_PKG_NAME"), 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,
}
#[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),
Send(SendCommand),
#[command(subcommand)]
Info(InfoCommand),
Attach { _ignored: Vec<String> },
Shutdown(ShutdownCommand),
#[command(subcommand)]
Healthcheck(HealthcheckCommand),
}
pub(super) fn format_vec_pretty(vec: Vec<String>) -> String {
format!("[{}]", vec.join(", "))
}
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_cids(tipset: Tipset) -> anyhow::Result<()> {
for cid in &tipset.cids() {
println!("{cid}");
}
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)
}