Skip to content

Commit

Permalink
Merge pull request #1215 from matklad/subcommand-isnt-a-typo
Browse files Browse the repository at this point in the history
Disable typo suggestions in presence of external subcommands
  • Loading branch information
kbknapp authored Mar 19, 2018
2 parents b909132 + a410e85 commit 32f3c18
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/app/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ where
}

if !(self.is_set(AS::ArgsNegateSubcommands) && self.is_set(AS::ValidArgFound))
&& !self.is_set(AS::InferSubcommands)
&& !self.is_set(AS::InferSubcommands) && !self.is_set(AS::AllowExternalSubcommands)
{
if let Some(cdate) =
suggestions::did_you_mean(&*arg_os.to_string_lossy(), sc_names!(self))
Expand All @@ -994,7 +994,7 @@ where
let low_index_mults = self.is_set(AS::LowIndexMultiplePositional)
&& pos_counter == (self.positionals.len() - 1);
let missing_pos = self.is_set(AS::AllowMissingPositional)
&& (pos_counter == (self.positionals.len() - 1)
&& (pos_counter == (self.positionals.len() - 1)
&& !self.is_set(AS::TrailingValues));
debugln!(
"Parser::get_matches_with: Positional counter...{}",
Expand Down
24 changes: 21 additions & 3 deletions tests/app_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ fn missing_positional_hyphen_req_error() {
#[test]
fn issue_1066_allow_leading_hyphen_and_unknown_args() {
let res = App::new("prog")
.global_setting(AppSettings::AllowLeadingHyphen)
.global_setting(AppSettings::AllowLeadingHyphen)
.arg(Arg::from_usage("--some-argument"))
.get_matches_from_safe(vec!["prog", "hello"]);

Expand All @@ -728,7 +728,7 @@ fn issue_1066_allow_leading_hyphen_and_unknown_args() {
#[test]
fn issue_1066_allow_leading_hyphen_and_unknown_args_no_vals() {
let res = App::new("prog")
.global_setting(AppSettings::AllowLeadingHyphen)
.global_setting(AppSettings::AllowLeadingHyphen)
.arg(Arg::from_usage("--some-argument"))
.get_matches_from_safe(vec!["prog", "--hello"]);

Expand All @@ -739,7 +739,7 @@ fn issue_1066_allow_leading_hyphen_and_unknown_args_no_vals() {
#[test]
fn issue_1066_allow_leading_hyphen_and_unknown_args_option() {
let res = App::new("prog")
.global_setting(AppSettings::AllowLeadingHyphen)
.global_setting(AppSettings::AllowLeadingHyphen)
.arg(Arg::from_usage("--some-argument=[val]"))
.get_matches_from_safe(vec!["prog", "-hello"]);

Expand All @@ -755,6 +755,24 @@ fn issue_1093_allow_ext_sc() {
assert!(test::compare_output(app, "clap-test --help", ALLOW_EXT_SC, false));
}

#[test]
fn external_subcommand_looks_like_built_in() {
let res = App::new("cargo")
.version("1.26.0")
.setting(AppSettings::AllowExternalSubcommands)
.subcommand(SubCommand::with_name("install"))
.get_matches_from_safe(vec!["cargo", "install-update", "foo"]);
assert!(res.is_ok());
let m = res.unwrap();
match m.subcommand() {
(name, Some(args)) => {
assert_eq!(name, "install-update");
assert_eq!(args.values_of_lossy(""), Some(vec!["foo".to_string()]));
}
_ => assert!(false),
}
}

#[test]
fn aaos_flags() {
// flags
Expand Down

0 comments on commit 32f3c18

Please sign in to comment.