Skip to main content

solana_tools_lite_cli/models/
cmds.rs

1use clap::{ArgGroup, Subcommand};
2
3#[derive(Subcommand, Debug)]
4pub enum Commands {
5    /// Generate a new mnemonic and keypair, or derive from existing mnemonic
6    Gen {
7        /// Read mnemonic from file or stdin ("-"). If omitted, a new mnemonic is generated.
8        #[arg(long, value_name = "FILE")]
9        mnemonic: Option<String>,
10        /// Read passphrase from file or stdin ("-"). Optional.
11        #[arg(long, value_name = "FILE")]
12        passphrase: Option<String>,
13        /// UNSAFE: print secret to stdout
14        #[arg(long = "unsafe-show-secret", default_value = "false")]
15        unsafe_show_secret: bool,
16        /// Output path for a wallet
17        #[arg(long, short)]
18        output: Option<String>,
19        /// Force save(override) a wallet file [env: SOLANA_TOOLS_LITE_FORCE]
20        #[arg(long, short, default_value = "false")]
21        force: bool,
22    },
23
24    /// Sign a message
25    #[command(group(ArgGroup::new("data_source").required(true).args(["message", "from_file"])))]
26    Sign {
27        /// Message to sign (inline)
28        #[arg(short, long, group = "data_source")]
29        message: Option<String>,
30
31        /// Read message from file or stdin ("-")
32        #[arg(long = "from-file", value_name = "FILE", group = "data_source")]
33        from_file: Option<String>,
34
35        /// Path to keypair file (stdin disabled for secrets) [env: SOLANA_SIGNER_KEYPAIR]
36        #[arg(long, short = 'k')]
37        keypair: Option<String>,
38
39        /// Optional output file (if not set, print to stdout)
40        #[arg(long, short)]
41        output: Option<String>,
42
43        /// Force save(override) a file [env: SOLANA_TOOLS_LITE_FORCE]
44        #[arg(long, short, default_value = "false")]
45        force: bool,
46    },
47
48    /// Verify a signature
49    #[command(group(ArgGroup::new("msg_src").required(true).args(["message", "from_file"])))]
50    #[command(group(ArgGroup::new("sig_src").required(true).args(["signature", "signature_file"])))]
51    #[command(group(ArgGroup::new("pk_src").required(true).args(["pubkey", "pubkey_file"])))]
52    Verify {
53        /// Message to verify (inline)
54        #[arg(short, long, group = "msg_src")]
55        message: Option<String>,
56
57        /// Read message from file or stdin ("-")
58        /// Accepts both `--from-file` and `--message-file` for convenience.
59        #[arg(
60            long = "from-file",
61            alias = "message-file",
62            value_name = "FILE",
63            group = "msg_src"
64        )]
65        from_file: Option<String>,
66
67        /// Signature to verify (Base58, inline)
68        #[arg(short, long, group = "sig_src")]
69        signature: Option<String>,
70
71        /// Read signature from file or stdin ("-")
72        #[arg(long = "signature-file", value_name = "FILE", group = "sig_src")]
73        signature_file: Option<String>,
74
75        /// Public key (Base58, inline)
76        #[arg(long, group = "pk_src")]
77        pubkey: Option<String>,
78
79        /// Read public key from file or stdin ("-")
80        #[arg(long = "pubkey-file", value_name = "FILE", group = "pk_src")]
81        pubkey_file: Option<String>,
82
83        /// Optional output file (if not set, print to stdout)
84        #[arg(long, short = 'o')]
85        output: Option<String>,
86
87        /// Force save(override) a file [env: SOLANA_TOOLS_LITE_FORCE]
88        #[arg(long, short, default_value = "false")]
89        force: bool,
90    },
91
92    /// Base58 encode/decode
93    Base58 {
94        #[command(subcommand)]
95        action: Base58Action,
96    },
97
98    /// Sign a transaction file (JSON/Base64/Base58)
99    SignTx {
100        /// Path to input transaction (UI JSON/Base64/Base58)
101        #[arg(long, short = 'i')]
102        input: String,
103
104        /// Optional lookup table file (JSON map: table address -> array of addresses)
105        #[arg(long = "tables", value_name = "FILE")]
106        lookup_tables: Option<String>,
107
108        /// Path to keypair file (stdin disabled for secrets) [env: SOLANA_SIGNER_KEYPAIR]
109        #[arg(long, short = 'k')]
110        keypair: Option<String>,
111
112        /// Optional output file (if not set, print to stdout)
113        #[arg(long, short = 'o')]
114        output: Option<String>,
115
116        /// Force output format (json|base64|base58). If not specified, we mirror the input format. [env: SOLANA_TOOLS_LITE_OUTPUT_FORMAT]
117        #[arg(long = "output-format", value_enum)]
118        output_format: Option<OutFmt>,
119
120        /// Force save(override) the output file when it exists [env: SOLANA_TOOLS_LITE_FORCE]
121        #[arg(long, short, default_value = "false")]
122        force: bool,
123
124        /// Auto-approve without interactive prompt (useful for CI/pipelines) [env: SOLANA_TOOLS_LITE_YES]
125        #[arg(long = "yes", short = 'y', action = clap::ArgAction::SetTrue)]
126        assume_yes: bool,
127
128        /// Fail if total fee (base + priority) exceeds this limit (lamports) [env: SOLANA_TOOLS_LITE_MAX_FEE]
129        #[arg(long = "max-fee", value_name = "LAMPORTS")]
130        max_fee: Option<u64>,
131
132        /// Emit signing summary as JSON to stdout (requires --output for signed tx)
133        #[arg(long = "summary-json", default_value = "false")]
134        summary_json: bool,
135    },
136
137    /// Analyze a transaction file (JSON/Base64/Base58)
138    Analyze {
139        /// Path to input transaction (UI JSON/Base64/Base58)
140        #[arg(long, short = 'i')]
141        input: String,
142
143        /// Optional lookup table file (JSON map: table address -> array of addresses)
144        #[arg(long = "tables", value_name = "FILE")]
145        lookup_tables: Option<String>,
146
147        /// Public key to analyze as (Base58). If not provided, uses first signer from message.
148        #[arg(long, short = 'p')]
149        pubkey: Option<String>,
150
151        /// Emit analysis summary as JSON to stdout
152        #[arg(long = "summary-json", default_value = "false")]
153        summary_json: bool,
154    },
155}
156
157#[derive(Subcommand, Debug)]
158pub enum Base58Action {
159    Encode {
160        #[arg(short, long)]
161        input: String,
162    },
163    Decode {
164        #[arg(short, long)]
165        input: String,
166    },
167}
168
169#[derive(clap::ValueEnum, Clone, Copy, Debug)]
170pub enum OutFmt {
171    Json,
172    Base64,
173    Base58,
174}