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

min_values(0) still complains about no value when combining short versions #2624

Closed
2 tasks done
miDeb opened this issue Jul 26, 2021 · 3 comments · Fixed by #2643
Closed
2 tasks done

min_values(0) still complains about no value when combining short versions #2624

miDeb opened this issue Jul 26, 2021 · 3 comments · Fixed by #2643
Labels
C-bug Category: Updating dependencies

Comments

@miDeb
Copy link

miDeb commented Jul 26, 2021

Please complete the following tasks

  • I have searched the discussions
  • I have searched the existing issues

Rust Version

rustc 1.56.0-nightly (9c25eb7aa 2021-07-25)

Clap Version

2.33

Minimal reproducible code

use clap::{App, Arg};

fn main() {
    let matches = App::new("foo")
        .arg(
            Arg::with_name("check")
                .short("c")
                .long("check")
                .takes_value(true)
                .require_equals(true)
                .min_values(0)
                .possible_values(&["silent", "quiet", "diagnose-first"])
                .help("check for sorted input; do not sort"),
        )
        .arg(
            Arg::with_name("unique")
                .short("u")
                .long("unique")
                .help("output only the first of an equal run"),
        )
        .get_matches();
    assert!(matches.is_present("check"));
    assert!(matches.is_present("unique"));
}

Steps to reproduce the bug with the above code

cargo r -- -cu

Actual Behaviour

error: The argument '--check=<check>' requires a value but none was supplied

USAGE:
    clap-bug [FLAGS] [OPTIONS]

For more information try --help

Expected Behaviour

The same thing that happens when invoking the program like this: cargo r -- -u -c, which should be synomymous to -cu.
The program would succeed and produce no output.

Additional Context

No response

Debug Output

DEBUG:clap:Parser::propagate_settings: self=foo, g_settings=AppFlags(
    (empty),
)
DEBUG:clap:Parser::get_matches_with;
DEBUG:clap:Parser::create_help_and_version;
DEBUG:clap:Parser::create_help_and_version: Building --help
DEBUG:clap:Parser::create_help_and_version: Building --version
DEBUG:clap:Parser::get_matches_with: Begin parsing '"-cu"' ([45, 99, 117])
DEBUG:clap:Parser::is_new_arg:"-cu":NotFound
DEBUG:clap:Parser::is_new_arg: arg_allows_tac=false
DEBUG:clap:Parser::is_new_arg: - found
DEBUG:clap:Parser::is_new_arg: starts_new_arg=true
DEBUG:clap:Parser::possible_subcommand: arg="-cu"
DEBUG:clap:Parser::get_matches_with: possible_sc=false, sc=None
DEBUG:clap:ArgMatcher::process_arg_overrides:None;
DEBUG:clap:Parser::parse_short_arg: full_arg="-cu"
DEBUG:clap:Parser::parse_short_arg:iter:c
DEBUG:clap:Parser::parse_short_arg:iter:c: Found valid opt
DEBUG:clap:Parser::parse_short_arg:iter:c: p[0]=[], p[1]=[117]
DEBUG:clap:Parser::parse_short_arg:iter:c: val=[117] (bytes), val="u" (ascii)
DEBUG:clap:Parser::parse_opt; opt=check, val=Some("u")
DEBUG:clap:Parser::parse_opt; opt.settings=ArgFlags(TAKES_VAL | DELIM_NOT_SET | REQUIRE_EQUALS)
DEBUG:clap:Parser::parse_opt; Checking for val...Found Empty - Error
DEBUG:clap:usage::create_usage_with_title;
DEBUG:clap:usage::create_usage_no_title;
DEBUG:clap:usage::get_required_usage_from: reqs=[], extra=None
DEBUG:clap:usage::get_required_usage_from: after init desc_reqs=[]
DEBUG:clap:usage::get_required_usage_from: no more children
DEBUG:clap:usage::get_required_usage_from: final desc_reqs=[]
DEBUG:clap:usage::get_required_usage_from: args_in_groups=[]
DEBUG:clap:usage::needs_flags_tag;
DEBUG:clap:usage::needs_flags_tag:iter: f=unique;
DEBUG:clap:Parser::groups_for_arg: name=unique
DEBUG:clap:Parser::groups_for_arg: No groups defined
DEBUG:clap:usage::needs_flags_tag:iter: [FLAGS] required
DEBUG:clap:usage::create_help_usage: usage=clap-bug [FLAGS] [OPTIONS]
DEBUG:clap:Parser::color;
DEBUG:clap:Parser::color: Color setting...Auto
DEBUG:clap:is_a_tty: stderr=true
DEBUG:clap:Colorizer::error;
DEBUG:clap:OptBuilder::fmt:check
DEBUG:clap:Colorizer::warning;
DEBUG:clap:Colorizer::good;
error: The argument '--check=<check>' requires a value but none was supplied

USAGE:
    clap-bug [FLAGS] [OPTIONS]

For more information try --help
@miDeb miDeb added the C-bug Category: Updating dependencies label Jul 26, 2021
@epage
Copy link
Member

epage commented Jul 26, 2021

Looks to be an ordering issue. We pull out the value before checking RequireEquals

I feel like this is something that would be made easier to fix once we've refactored to having a dedicated lexer, see #2615

@ldm0
Copy link
Member

ldm0 commented Jul 26, 2021

Current master behaviour:

use clap::{App, Arg};
fn main() {
    let matches = App::new("foo")
        .arg(
            Arg::new("check")
                .short('c')
                .long("check")
                .require_equals(true)
                .min_values(0)
                .possible_values(&["silent", "quiet", "diagnose-first"]),
        )
        .arg(
            Arg::new("unique")
                .short('u')
                .long("unique")
        )
        .get_matches();
    assert!(matches.is_present("check"));
    assert!(matches.is_present("unique"));
}
error: "u" isn't a valid value for '--check=<check>...'
        [possible values: diagnose-first, quiet, silent]

USAGE:
    rust_test2 --check=<check>...

For more information try --help

@miDeb
Copy link
Author

miDeb commented Jul 26, 2021

This looks like it doesn't take require_equals(true) into account on current master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Updating dependencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants