1use {
2 crate::{
3 address_lookup_table::AddressLookupTableSubCommands, cli::*, cluster_query::*, feature::*,
4 inflation::*, nonce::*, program::*, program_v4::ProgramV4SubCommands, stake::*,
5 validator_info::*, vote::*, wallet::*,
6 },
7 clap::{App, AppSettings, Arg, ArgGroup, SubCommand},
8 solana_clap_utils::{self, hidden_unless_forced, input_validators::*, keypair::*},
9 solana_cli_config::CONFIG_FILE,
10};
11
12pub fn get_clap_app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, 'v> {
13 App::new(name)
14 .about(about)
15 .version(version)
16 .setting(AppSettings::SubcommandRequiredElseHelp)
17 .arg(
18 Arg::with_name("skip_preflight")
19 .long("skip-preflight")
20 .global(true)
21 .takes_value(false)
22 .help("Skip the preflight check when sending transactions"),
23 )
24 .arg({
25 let arg = Arg::with_name("config_file")
26 .short("C")
27 .long("config")
28 .value_name("FILEPATH")
29 .takes_value(true)
30 .global(true)
31 .help("Configuration file to use");
32 if let Some(ref config_file) = *CONFIG_FILE {
33 arg.default_value(config_file)
34 } else {
35 arg
36 }
37 })
38 .arg(
39 Arg::with_name("json_rpc_url")
40 .short("u")
41 .long("url")
42 .value_name("URL_OR_MONIKER")
43 .takes_value(true)
44 .global(true)
45 .validator(is_url_or_moniker)
46 .help(
47 "URL for Solana's JSON RPC or moniker (or their first letter): [mainnet-beta, \
48 testnet, devnet, localhost]",
49 ),
50 )
51 .arg(
52 Arg::with_name("websocket_url")
53 .long("ws")
54 .value_name("URL")
55 .takes_value(true)
56 .global(true)
57 .validator(is_url)
58 .help("WebSocket URL for the solana cluster"),
59 )
60 .arg(
61 Arg::with_name("keypair")
62 .short("k")
63 .long("keypair")
64 .value_name("KEYPAIR")
65 .global(true)
66 .takes_value(true)
67 .help("Filepath or URL to a keypair"),
68 )
69 .arg(
70 Arg::with_name("commitment")
71 .long("commitment")
72 .takes_value(true)
73 .possible_values(&[
74 "processed",
75 "confirmed",
76 "finalized",
77 "recent", "single", "singleGossip", "root", "max", ])
83 .value_name("COMMITMENT_LEVEL")
84 .hide_possible_values(true)
85 .global(true)
86 .help(
87 "Return information at the selected commitment level [possible values: \
88 processed, confirmed, finalized]",
89 ),
90 )
91 .arg(
92 Arg::with_name("verbose")
93 .long("verbose")
94 .short("v")
95 .global(true)
96 .help("Show additional information"),
97 )
98 .arg(
99 Arg::with_name("use_tpu_client")
100 .long("use-tpu-client")
101 .global(true)
102 .help("Use TPU client when sending transactions."),
103 )
104 .arg(
105 Arg::with_name("no_address_labels")
106 .long("no-address-labels")
107 .global(true)
108 .help("Do not use address labels in the output"),
109 )
110 .arg(
111 Arg::with_name("output_format")
112 .long("output")
113 .value_name("FORMAT")
114 .global(true)
115 .takes_value(true)
116 .possible_values(&["json", "json-compact"])
117 .help("Return information in specified output format"),
118 )
119 .arg(
120 Arg::with_name(SKIP_SEED_PHRASE_VALIDATION_ARG.name)
121 .long(SKIP_SEED_PHRASE_VALIDATION_ARG.long)
122 .global(true)
123 .help(SKIP_SEED_PHRASE_VALIDATION_ARG.help),
124 )
125 .arg(
126 Arg::with_name("rpc_timeout")
127 .long("rpc-timeout")
128 .value_name("SECONDS")
129 .takes_value(true)
130 .default_value(DEFAULT_RPC_TIMEOUT_SECONDS)
131 .global(true)
132 .hidden(hidden_unless_forced())
133 .help("Timeout value for RPC requests"),
134 )
135 .arg(
136 Arg::with_name("confirm_transaction_initial_timeout")
137 .long("confirm-timeout")
138 .value_name("SECONDS")
139 .takes_value(true)
140 .default_value(DEFAULT_CONFIRM_TX_TIMEOUT_SECONDS)
141 .global(true)
142 .hidden(hidden_unless_forced())
143 .help("Timeout value for initial transaction status"),
144 )
145 .cluster_query_subcommands()
146 .feature_subcommands()
147 .inflation_subcommands()
148 .nonce_subcommands()
149 .program_subcommands()
150 .program_v4_subcommands()
151 .address_lookup_table_subcommands()
152 .stake_subcommands()
153 .validator_info_subcommands()
154 .vote_subcommands()
155 .wallet_subcommands()
156 .subcommand(
157 SubCommand::with_name("config")
158 .about("Solana command-line tool configuration settings")
159 .aliases(&["get", "set"])
160 .setting(AppSettings::SubcommandRequiredElseHelp)
161 .subcommand(
162 SubCommand::with_name("get")
163 .about("Get current config settings")
164 .arg(
165 Arg::with_name("specific_setting")
166 .index(1)
167 .value_name("CONFIG_FIELD")
168 .takes_value(true)
169 .possible_values(&[
170 "json_rpc_url",
171 "websocket_url",
172 "keypair",
173 "commitment",
174 ])
175 .help("Return a specific config setting"),
176 ),
177 )
178 .subcommand(
179 SubCommand::with_name("set")
180 .about("Set a config setting")
181 .group(
182 ArgGroup::with_name("config_settings")
183 .args(&["json_rpc_url", "websocket_url", "keypair", "commitment"])
184 .multiple(true)
185 .required(true),
186 ),
187 )
188 .subcommand(
189 SubCommand::with_name("import-address-labels")
190 .about("Import a list of address labels")
191 .arg(
192 Arg::with_name("filename")
193 .index(1)
194 .value_name("FILENAME")
195 .takes_value(true)
196 .help("YAML file of address labels"),
197 ),
198 )
199 .subcommand(
200 SubCommand::with_name("export-address-labels")
201 .about("Export the current address labels")
202 .arg(
203 Arg::with_name("filename")
204 .index(1)
205 .value_name("FILENAME")
206 .takes_value(true)
207 .help("YAML file to receive the current address labels"),
208 ),
209 ),
210 )
211 .subcommand(
212 SubCommand::with_name("completion")
213 .about("Generate completion scripts for various shells")
214 .arg(
215 Arg::with_name("shell")
216 .long("shell")
217 .short("s")
218 .takes_value(true)
219 .possible_values(&["bash", "fish", "zsh", "powershell", "elvish"])
220 .default_value("bash"),
221 ),
222 )
223}