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