trdelnik_sandbox_cli/
lib.rs

1use anyhow::Error;
2use clap::{Parser, Subcommand};
3use fehler::throws;
4
5// subcommand functions to call and nested subcommands
6mod command;
7// bring nested subcommand enums into scope
8use command::ExplorerCommand;
9use command::KeyPairCommand;
10
11#[derive(Parser)]
12#[clap(version, propagate_version = true)]
13struct Cli {
14    #[clap(subcommand)]
15    command: Command,
16}
17
18#[derive(Subcommand)]
19enum Command {
20    /// Create a `program_client` crate
21    Build {
22        /// Anchor project root
23        #[clap(short, long, default_value = "./")]
24        root: String,
25    },
26    /// Get information about a keypair
27    KeyPair {
28        #[clap(subcommand)]
29        subcmd: KeyPairCommand,
30    },
31    /// Run program tests
32    Test {
33        /// Anchor project root
34        #[clap(short, long, default_value = "./")]
35        root: String,
36    },
37    /// Run local test validator
38    Localnet,
39    /// The Hacker's Explorer
40    Explorer {
41        #[clap(subcommand)]
42        subcmd: ExplorerCommand,
43    },
44    /// Initialize test environment
45    Init,
46}
47
48#[throws]
49pub async fn start() {
50    let cli = Cli::parse();
51
52    match cli.command {
53        Command::Build { root } => command::build(root).await?,
54        Command::KeyPair { subcmd } => command::keypair(subcmd)?,
55        Command::Test { root } => command::test(root).await?,
56        Command::Localnet => command::localnet().await?,
57        Command::Explorer { subcmd } => command::explorer(subcmd).await?,
58        Command::Init => command::init().await?,
59    }
60}