From 1000c9fb0321b9dde62c35cf273993feaca56635 Mon Sep 17 00:00:00 2001 From: ldm0 Date: Sat, 23 Jan 2021 07:18:55 +0000 Subject: [PATCH] Fix eagerly trimming dash in parse_long_flag --- src/parse/parser.rs | 3 ++- tests/flags.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/parse/parser.rs b/src/parse/parser.rs index b3e988d5aa3..a3617a7a273 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -1007,7 +1007,7 @@ impl<'help, 'app> Parser<'help, 'app> { self.cur_idx.set(self.cur_idx.get() + 1); debug!("Parser::parse_long_arg: Does it contain '='..."); - let long_arg = full_arg.trim_start_matches(b'-'); + let long_arg = full_arg.trim_start_n_matches(2, b'-'); let (arg, val) = if full_arg.contains_byte(b'=') { let (p0, p1) = long_arg.split_at_byte(b'='); debug!("Yes '{:?}'", p1); @@ -1473,6 +1473,7 @@ impl<'help, 'app> Parser<'help, 'app> { // Error, Help, and Version Methods impl<'help, 'app> Parser<'help, 'app> { + /// Is only used for the long flag(which is the only one needs fuzzy searching) fn did_you_mean_error( &mut self, arg: &str, diff --git a/tests/flags.rs b/tests/flags.rs index 5e9016ba146..8502676ba01 100644 --- a/tests/flags.rs +++ b/tests/flags.rs @@ -146,3 +146,24 @@ fn issue_1284_argument_in_flag_style() { true )); } + +#[test] +fn issue_2308_multiple_dashes() { + static MULTIPLE_DASHES: &str = + "error: Found argument '-----' which wasn't expected, or isn't valid in this context + + If you tried to supply `-----` as a value rather than a flag, use `-- -----` + +USAGE: + test + +For more information try --help"; + let app = App::new("test").arg(Arg::new("arg").takes_value(true).required(true)); + + assert!(utils::compare_output( + app, + "test -----", + MULTIPLE_DASHES, + true + )); +}