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

Produce an error for "compact" arguments where takes_value is false #2646

Closed
wants to merge 2 commits into from
Closed

Conversation

patrick-gu
Copy link
Contributor

Resolves #1543

The error message produced is: "error: Found argument '=false' which wasn't expected, or isn't valid in this context". This uses ClapError::unknown_argument.

It might be better to remove the "=". If this would be better, I think it would also make sense to not produce the error when "--flag=" is used.

@epage
Copy link
Member

epage commented Jul 30, 2021

If I'm reading this correctly, this looks like it solves the same problem as #2619 (just didn't have the Issue associated with it).

Are they the same? What are your thoughts on the trade offs between the two approaches?

@ldm0 ldm0 self-requested a review July 30, 2021 19:33
Copy link
Member

@ldm0 ldm0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -1076,6 +1077,13 @@ impl<'help, 'app> Parser<'help, 'app> {
self.seen.push(opt.id.clone());
if opt.is_set(ArgSettings::TakesValue) {
return self.parse_opt(&val, opt, matcher);
} else if let Some(val) = val {
return Err(ClapError::unknown_argument(
Copy link
Member

@ldm0 ldm0 Jul 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use ClapError::too_many_values here?

@patrick-gu
Copy link
Contributor Author

I didn't see #2619 before making this, but it seems more thorough than this. Using the too many values error might make more sense to users.

@patrick-gu patrick-gu closed this Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Arguments with takes_value(false) still accept "compact"-style arguments
3 participants