Make CLI arguments parsing more backwards compatible
This commit is contained in:
@@ -24,6 +24,7 @@ usage! {
|
||||
// Subcommands must start with cmd_ and have '_' in place of '-'
|
||||
// Sub-subcommands must start with the name of the subcommand
|
||||
// Arguments must start with arg_
|
||||
// Flags must start with flag_
|
||||
|
||||
CMD cmd_ui {
|
||||
"Manage ui",
|
||||
@@ -53,10 +54,6 @@ usage! {
|
||||
|
||||
CMD cmd_account_new {
|
||||
"Create a new acount",
|
||||
|
||||
ARG arg_account_new_password: (Option<String>) = None,
|
||||
"--password=[FILE]",
|
||||
"Path to the password file",
|
||||
}
|
||||
|
||||
CMD cmd_account_list {
|
||||
@@ -81,10 +78,6 @@ usage! {
|
||||
{
|
||||
"Import wallet",
|
||||
|
||||
ARG arg_wallet_import_password: (Option<String>) = None,
|
||||
"--password=[FILE]",
|
||||
"Path to the password file",
|
||||
|
||||
ARG arg_wallet_import_path: (Option<String>) = None,
|
||||
"<PATH>",
|
||||
"Path to the wallet",
|
||||
@@ -179,10 +172,6 @@ usage! {
|
||||
{
|
||||
"Sign",
|
||||
|
||||
ARG arg_signer_sign_password: (Option<String>) = None,
|
||||
"--password=[FILE]",
|
||||
"Path to the password file",
|
||||
|
||||
ARG arg_signer_sign_id: (Option<usize>) = None,
|
||||
"[ID]",
|
||||
"ID",
|
||||
@@ -244,7 +233,7 @@ usage! {
|
||||
}
|
||||
}
|
||||
{
|
||||
// Flags and arguments
|
||||
// Global flags and arguments
|
||||
["Operating Options"]
|
||||
FLAG flag_public_node: (bool) = false, or |c: &Config| otry!(c.parity).public_node.clone(),
|
||||
"--public-node",
|
||||
@@ -353,7 +342,6 @@ usage! {
|
||||
ARG arg_password: (Vec<String>) = Vec::new(), or |c: &Config| otry!(c.account).password.clone(),
|
||||
"--password=[FILE]...",
|
||||
"Provide a file containing a password for unlocking an account. Leading and trailing whitespace is trimmed.",
|
||||
|
||||
["UI options"]
|
||||
FLAG flag_force_ui: (bool) = false, or |c: &Config| otry!(c.ui).force.clone(),
|
||||
"--force-ui",
|
||||
@@ -840,6 +828,10 @@ usage! {
|
||||
"Target size of the whisper message pool in megabytes.",
|
||||
|
||||
["Legacy options"]
|
||||
FLAG flag_warp: (bool) = false, or |_| None,
|
||||
"--warp",
|
||||
"Does nothing; warp sync is enabled by default.",
|
||||
|
||||
FLAG flag_dapps_apis_all: (bool) = false, or |_| None,
|
||||
"--dapps-apis-all",
|
||||
"Dapps server is merged with RPC server. Use --jsonrpc-apis.",
|
||||
@@ -1208,6 +1200,29 @@ mod tests {
|
||||
use toml;
|
||||
use clap::{ErrorKind as ClapErrorKind};
|
||||
|
||||
#[test]
|
||||
fn should_accept_any_argument_order() {
|
||||
let args = Args::parse(&["parity", "--no-warp", "account", "list"]).unwrap();
|
||||
assert_eq!(args.flag_no_warp, true);
|
||||
|
||||
let args = Args::parse(&["parity", "account", "list", "--no-warp"]).unwrap();
|
||||
assert_eq!(args.flag_no_warp, true);
|
||||
|
||||
let args = Args::parse(&["parity", "--chain=dev", "account", "list"]).unwrap();
|
||||
assert_eq!(args.arg_chain, "dev");
|
||||
|
||||
let args = Args::parse(&["parity", "account", "list", "--chain=dev"]).unwrap();
|
||||
assert_eq!(args.arg_chain, "dev");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_not_crash_on_warp() {
|
||||
let args = Args::parse(&["parity", "--warp"]);
|
||||
assert!(args.is_ok());
|
||||
|
||||
let args = Args::parse(&["parity", "account", "list", "--warp"]);
|
||||
assert!(args.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_reject_invalid_values() {
|
||||
@@ -1380,9 +1395,6 @@ mod tests {
|
||||
arg_restore_file: None,
|
||||
arg_tools_hash_file: None,
|
||||
|
||||
arg_account_new_password: None,
|
||||
arg_signer_sign_password: None,
|
||||
arg_wallet_import_password: None,
|
||||
arg_signer_sign_id: None,
|
||||
arg_signer_reject_id: None,
|
||||
arg_dapp_path: None,
|
||||
@@ -1565,6 +1577,7 @@ mod tests {
|
||||
arg_whisper_pool_size: 20,
|
||||
|
||||
// -- Legacy Options
|
||||
flag_warp: false,
|
||||
flag_geth: false,
|
||||
flag_testnet: false,
|
||||
flag_import_geth_keys: false,
|
||||
|
||||
Reference in New Issue
Block a user