Graceful exit when invalid CLI flags are passed (#6485)
This commit is contained in:
parent
7029dda87c
commit
a101a23ba3
@ -1201,6 +1201,7 @@ mod tests {
|
|||||||
Snapshots, VM, Misc, Whisper, SecretStore,
|
Snapshots, VM, Misc, Whisper, SecretStore,
|
||||||
};
|
};
|
||||||
use toml;
|
use toml;
|
||||||
|
use clap::{ErrorKind as ClapErrorKind};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_parse_args_and_flags() {
|
fn should_parse_args_and_flags() {
|
||||||
@ -1217,6 +1218,17 @@ mod tests {
|
|||||||
assert_eq!(args.arg_export_state_min_balance, Some("123".to_string()));
|
assert_eq!(args.arg_export_state_min_balance, Some("123".to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_exit_gracefully_on_unknown_argument() {
|
||||||
|
let result = Args::parse(&["parity", "--please-exit-gracefully"]);
|
||||||
|
assert!(
|
||||||
|
match result {
|
||||||
|
Err(ArgsError::Clap(ref clap_error)) if clap_error.kind == ClapErrorKind::UnknownArgument => true,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_use_subcommand_arg_default() {
|
fn should_use_subcommand_arg_default() {
|
||||||
let args = Args::parse(&["parity", "export", "state", "--at", "123"]).unwrap();
|
let args = Args::parse(&["parity", "export", "state", "--at", "123"]).unwrap();
|
||||||
|
@ -537,21 +537,20 @@ macro_rules! usage {
|
|||||||
|
|
||||||
let matches = App::new("Parity")
|
let matches = App::new("Parity")
|
||||||
.global_setting(AppSettings::VersionlessSubcommands)
|
.global_setting(AppSettings::VersionlessSubcommands)
|
||||||
.global_setting(AppSettings::AllowLeadingHyphen) // allow for example --allow-ips -10.0.0.0/8
|
|
||||||
.global_setting(AppSettings::DisableHelpSubcommand)
|
.global_setting(AppSettings::DisableHelpSubcommand)
|
||||||
.help(Args::print_help().as_ref())
|
.help(Args::print_help().as_ref())
|
||||||
.args(&usages.iter().map(|u| Arg::from_usage(u).use_delimiter(false)).collect::<Vec<Arg>>())
|
.args(&usages.iter().map(|u| Arg::from_usage(u).use_delimiter(false).allow_hyphen_values(true)).collect::<Vec<Arg>>())
|
||||||
$(
|
$(
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name(&underscore_to_hyphen!(&stringify!($subc)[4..]))
|
SubCommand::with_name(&underscore_to_hyphen!(&stringify!($subc)[4..]))
|
||||||
.about($subc_help)
|
.about($subc_help)
|
||||||
.args(&subc_usages.get(stringify!($subc)).unwrap().iter().map(|u| Arg::from_usage(u).use_delimiter(false)).collect::<Vec<Arg>>())
|
.args(&subc_usages.get(stringify!($subc)).unwrap().iter().map(|u| Arg::from_usage(u).use_delimiter(false).allow_hyphen_values(true)).collect::<Vec<Arg>>())
|
||||||
$(
|
$(
|
||||||
.setting(AppSettings::SubcommandRequired) // prevent from running `parity account`
|
.setting(AppSettings::SubcommandRequired) // prevent from running `parity account`
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name(&underscore_to_hyphen!(&stringify!($subc_subc)[stringify!($subc).len()+1..]))
|
SubCommand::with_name(&underscore_to_hyphen!(&stringify!($subc_subc)[stringify!($subc).len()+1..]))
|
||||||
.about($subc_subc_help)
|
.about($subc_subc_help)
|
||||||
.args(&subc_usages.get(stringify!($subc_subc)).unwrap().iter().map(|u| Arg::from_usage(u).use_delimiter(false)).collect::<Vec<Arg>>())
|
.args(&subc_usages.get(stringify!($subc_subc)).unwrap().iter().map(|u| Arg::from_usage(u).use_delimiter(false).allow_hyphen_values(true)).collect::<Vec<Arg>>())
|
||||||
)
|
)
|
||||||
)*
|
)*
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user