mod arguments;
mod balance;
mod cl_type;
mod cl_value;
mod config;
mod contract_runtime;
mod network;
mod secure_storage;
pub mod storage;
mod transaction;
pub mod utils;
mod view_account;
mod wallet;
use anyhow::Result;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser)]
#[command(
name = "casper-cli",
version,
about = "Casper Network command-line interface"
)]
struct Cli {
#[arg(long, global = true)]
no_interactive: bool,
#[arg(long, global = true, conflicts_with = "file_storage")]
keyring: bool,
#[arg(
long,
global = true,
value_name = "ROOT_PATH",
conflicts_with = "keyring"
)]
file_storage: Option<PathBuf>,
#[arg(long, global = true, value_name = "PATH")]
config_path: Option<PathBuf>,
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Wallet(wallet::WalletArgs),
Network(network::NetworkArgs),
Config(config::ConfigArgs),
Balance(balance::BalanceArgs),
#[command(name = "transaction", alias = "tx")]
Transaction(transaction::TxArgs),
#[command(name = "view-account")]
ViewAccount(view_account::ViewAccountArgs),
}
fn main() -> Result<()> {
let cli = Cli::parse();
let config_path = match cli.config_path.clone() {
Some(path) => path,
None => network::default_config_path()?,
};
let storage_override = match (cli.keyring, cli.file_storage.as_ref()) {
(true, None) => Some(network::StorageOverride::Keyring),
(false, Some(path)) => Some(network::StorageOverride::File {
root_path: path.display().to_string(),
}),
_ => None,
};
let config_options = network::ConfigInitOptions {
no_interactive: cli.no_interactive,
storage_override,
};
let config_context = network::ConfigContext::new(config_path, config_options);
network::ensure_default_config_with_options(config_context.path(), config_context.options())?;
let storage = storage::StorageConfig::from_config(&config_context)?;
match cli.command {
Command::Wallet(command) => wallet::handle(&storage, &config_context, command),
Command::Network(command) => network::handle(&config_context, command),
Command::Config(command) => config::handle(&config_context, command),
Command::Balance(command) => balance::handle(&storage, &config_context, command),
Command::Transaction(command) => transaction::handle(&storage, &config_context, command),
Command::ViewAccount(command) => view_account::handle(&storage, &config_context, command),
}
}