Skip to content

default_missing_value does not respect delimiter #3761

Closed
@epage

Description

@epage

Please complete the following tasks

  • I have searched the discussions
    I have searched the open and rejected issues

Rust Version

rustc 1.57.0 (f1edd0429 2021-11-29)

Clap Version

3.1.13

Minimal reproducible code

#!/usr/bin/env rust-script

//! ```cargo
//! [dependencies]
//! clap = { path = "../clap", features = ["derive"] }
//! ```

fn main() {
    let cmd = clap::Command::new("foo").arg(
        clap::Arg::new("default")
            .short('f')
            .long("flag")
            .default_value("one,two")
            .min_values(0)
            .default_missing_value("three,four")
            .require_equals(true)
            .takes_value(true)
            .value_delimiter(','),
    );
    let matches = cmd.get_matches();
    println!("{:?}", matches);
}

Steps to reproduce the bug with the above code

$ ./clap-default.rs

$ ./clap-default.rs --flag

Actual Behaviour

$ ./clap-default.rs
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `/home/epage/src/personal/cargo-script-mvs/target/debug/rust-script ./clap-default.rs`
ArgMatches { args: {[hash: E880D196C5CA4253]: MatchedArg { occurs: 0, source: Some(DefaultValue), indices: [1, 2], type_id: Some(TypeId { t: 15399197027885530680 }), vals: [[AnyValue { inner: TypeId { t: 15399197027885530680 } }, AnyValue { inner: TypeId { t: 15399197027885530680 } }]], raw_vals: [["one", "two"]], ignore_case: false }}, subcommand: None }

$ ./clap-default.rs --flag
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `/home/epage/src/personal/cargo-script-mvs/target/debug/rust-script ./clap-default.rs --flag`
ArgMatches { args: {[hash: E880D196C5CA4253]: MatchedArg { occurs: 1, source: Some(CommandLine), indices: [2], type_id: Some(TypeId { t: 15399197027885530680 }), vals: [[AnyValue { inner: TypeId { t: 15399197027885530680 } }]], raw_vals: [["three,four"]], ignore_case: false }}, subcommand: None }

Expected Behaviour

$ ./clap-default.rs
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `/home/epage/src/personal/cargo-script-mvs/target/debug/rust-script ./clap-default.rs`
ArgMatches { args: {[hash: E880D196C5CA4253]: MatchedArg { occurs: 0, source: Some(DefaultValue), indices: [1, 2], type_id: Some(TypeId { t: 15399197027885530680 }), vals: [[AnyValue { inner: TypeId { t: 15399197027885530680 } }, AnyValue { inner: TypeId { t: 15399197027885530680 } }]], raw_vals: [["one", "two"]], ignore_case: false }}, subcommand: None }

$ ./clap-default.rs --flag
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `/home/epage/src/personal/cargo-script-mvs/target/debug/rust-script ./clap-default.rs --flag`
ArgMatches { args: {[hash: E880D196C5CA4253]: MatchedArg { occurs: 1, source: Some(CommandLine), indices: [2], type_id: Some(TypeId { t: 15399197027885530680 }), vals: [[AnyValue { inner: TypeId { t: 15399197027885530680 } }]], raw_vals: [["three", "four"]], ignore_case: false }}, subcommand: None }

Additional Context

By inspection, it looks like this worked when it was added, see #1587. It was further extended in #2172.

Looks like it was broken in #2297 when switching from add_arg_to_val to add_multiple_args_to_val

Debug Output

No response

Activity

added
C-bugCategory: bug
A-parsingArea: Parser's logic and needs it changed somehow.
E-easyCall for participation: Experience needed to fix: Easy / not much
on May 27, 2022
self-assigned this
on May 27, 2022
added a commit that references this issue on May 27, 2022
ccc809a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-parsingArea: Parser's logic and needs it changed somehow.C-bugCategory: bugE-easyCall for participation: Experience needed to fix: Easy / not much

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @epage

      Issue actions

        default_missing_value does not respect delimiter · Issue #3761 · clap-rs/clap