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

AppSettings::AllowLeadingHyphen makes app silence unknown unexpected arguments #1066

Closed
axelchalon opened this issue Oct 12, 2017 · 1 comment
Milestone

Comments

@axelchalon
Copy link

axelchalon commented Oct 12, 2017

rustc 1.18.0 / clap 2.26.0

When the global setting AllowLeadingHyphen is set and the app has at least one argument registered, Clap doesn't return an error if the program is called with an unknown, unexpected argument (it doesn't even have to start with a hyphen)

Sample Code / Steps to Reproduce the Issue

App::new("My program")
    .global_setting(AppSettings::AllowLeadingHyphen) 
    .arg(Arg::from_usage("--some-argument"))
    .get_matches();
$ program hello
... (program runs fine)

Output of get_matches() :
ArgMatches { args: {}, subcommand: None, usage: Some("USAGE:\n    program [FLAGS]") }
@kbknapp
Copy link
Member

kbknapp commented Oct 12, 2017

This should only happen if there is something expecting a value, i.e. if the unknown/unexpected argument could possibly be a value to some other argument (either positional or option). This is because clap can't really know if something starting with a hyphen is supposed to be a value, or just an incorrect flag/option.

If this isn't the case, i.e. there's no possible way it could be a valid value and it's still not detecting the error then that's a bug.

I haven't tested this yet on my machine as I'll have to do that when I get home, so this may very well be the bug you're suggesting 😉 I just wanted to lay out how this is supposed to work in a bug free world.

On a side note, if possible I recommend only using this setting for individual args via Arg::allow_hyphen_values

@kbknapp kbknapp added this to the 2.27.0 milestone Oct 12, 2017
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

No branches or pull requests

2 participants