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

Arg::value_parser does not implicitly set Arg::takes_value #4104

Closed
2 tasks done
wookietreiber opened this issue Aug 23, 2022 · 1 comment
Closed
2 tasks done

Arg::value_parser does not implicitly set Arg::takes_value #4104

wookietreiber opened this issue Aug 23, 2022 · 1 comment
Labels
C-bug Category: Updating dependencies

Comments

@wookietreiber
Copy link

Please complete the following tasks

Rust Version

rustc 1.63.0 (4b91a6ea7 2022-08-08)

Clap Version

3.2.17

Minimal reproducible code

fn main() {
    let digest = clap::Arg::with_name("digest")
        .short('d')
        .long("digest")
        .help("choose digest")
        .value_parser(["md5", "sha1"]);

    let cli = clap::Command::new("cmd").arg(digest);

    dbg!(cli.get_matches());
}

Steps to reproduce the bug with the above code

$ cargo run -- --help
   Compiling clap-value-parser-takes-value v0.1.0 (/home/umcdev/src/bug-reproduction/clap-value-parser-takes-value)
    Finished dev [unoptimized + debuginfo] target(s) in 0.91s
     Running `target/debug/clap-value-parser-takes-value --help`
cmd

USAGE:
    clap-value-parser-takes-value [OPTIONS]

OPTIONS:
    -d, --digest    choose digest
    -h, --help      Print help information

$ cargo run -- --digest md5
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/clap-value-parser-takes-value --digest md5`
error: Found argument 'md5' which wasn't expected, or isn't valid in this context

USAGE:
    clap-value-parser-takes-value [OPTIONS]

For more information try --help

Actual Behaviour

Arg::value_parse does not implicitly set Arg::takes_value.

Expected Behaviour

A lot of functions, e.g. Arg::value_name set Arg::takes_value(true) that I expected Arg::value_parser to do the same.

Additional Context

I consider this to be an inconsistency, it does not follow the principle of least surprise.

Debug Output

not required.

@wookietreiber wookietreiber added the C-bug Category: Updating dependencies label Aug 23, 2022
@epage
Copy link
Member

epage commented Aug 23, 2022

It might not be obvious at first but value_parser applies to flags as well as option and arguments.

The first case is defining how to parse environment variables.

The other is for non-bool flags

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Aug 23, 2022
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

No branches or pull requests

2 participants