pcli/
command.rs

1pub use debug::DebugCmd;
2pub use init::InitCmd;
3pub use migrate::MigrateCmd;
4pub use query::QueryCmd;
5pub use threshold::ThresholdCmd;
6pub use tx::TxCmd;
7pub use validator::ValidatorCmd;
8pub use view::ViewCmd;
9
10use self::tx::TxCmdWithOptions;
11
12mod debug;
13mod init;
14mod migrate;
15mod query;
16mod threshold;
17mod tx;
18mod utils;
19mod validator;
20mod view;
21
22// Note on display_order:
23//
24// The value is between 0 and 999 (the default).  Sorting of subcommands is done
25// by display_order first, and then alphabetically.  We should not try to order
26// every set of subcommands -- for instance, it doesn't make sense to try to
27// impose a non-alphabetical ordering on the query subcommands -- but we can use
28// the order to group related commands.
29//
30// Setting spaced numbers is future-proofing, letting us insert other commands
31// without noisy renumberings.
32//
33// https://docs.rs/clap/latest/clap/builder/struct.App.html#method.display_order
34#[derive(Debug, clap::Subcommand)]
35#[allow(clippy::large_enum_variant)]
36pub enum Command {
37    /// Initialize `pcli` with a new wallet, or reset it.
38    ///
39    /// This command requires selecting a custody backend.  The `SoftKMS`
40    /// backend is a good default choice.  More backends (e.g., threshold
41    /// custody, hardware wallets) may be added in the future.
42    #[clap(display_order = 100)]
43    Init(InitCmd),
44    /// Query the public chain state, like the validator set.
45    ///
46    /// This command has two modes: it can be used to query raw bytes of
47    /// arbitrary keys with the `key` subcommand, or it can be used to query
48    /// typed data with a subcommand for a particular component.
49    #[clap(subcommand, display_order = 200, visible_alias = "q")]
50    Query(QueryCmd),
51    /// View your private chain state, like account balances.
52    #[clap(subcommand, display_order = 300, visible_alias = "v")]
53    View(ViewCmd),
54    /// Create and broadcast a transaction.
55    #[clap(display_order = 400, visible_alias = "tx")]
56    Transaction(TxCmdWithOptions),
57    /// Follow the threshold signing protocol.
58    #[clap(subcommand, display_order = 500)]
59    Threshold(ThresholdCmd),
60    /// Migrate your balance to another wallet.
61    #[clap(subcommand, display_order = 600)]
62    Migrate(MigrateCmd),
63    /// Manage a validator.
64    #[clap(subcommand, display_order = 900)]
65    Validator(ValidatorCmd),
66    /// Display information related to diagnosing problems running Penumbra
67    #[clap(subcommand, display_order = 999)]
68    Debug(DebugCmd),
69}
70
71impl Command {
72    /// Determine if this command can run in "offline" mode.
73    pub fn offline(&self) -> bool {
74        match self {
75            Command::Init(_) => true,
76            Command::Transaction(cmd) => cmd.offline(),
77            Command::View(cmd) => cmd.offline(),
78            Command::Validator(cmd) => cmd.offline(),
79            Command::Query(cmd) => cmd.offline(),
80            Command::Debug(cmd) => cmd.offline(),
81            Command::Threshold(cmd) => cmd.offline(),
82            Command::Migrate(_) => false,
83        }
84    }
85}