Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eagerly trimming dash in parse_long_flag #2329

Merged
merged 1 commit into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions tests/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <arg>

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
));
}