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

UnknownArgumentValueParser eagerly errors out #5079

Closed
2 tasks done
weihanglo opened this issue Aug 18, 2023 · 2 comments · Fixed by #5080
Closed
2 tasks done

UnknownArgumentValueParser eagerly errors out #5079

weihanglo opened this issue Aug 18, 2023 · 2 comments · Fixed by #5080
Labels
C-bug Category: Updating dependencies

Comments

@weihanglo
Copy link

Please complete the following tasks

Rust Version

rustc 1.72.0-beta.8 (598a0a3cb 2023-08-12)

Clap Version

4.3.22

Minimal reproducible code

#!/usr/bin/env -S cargo +nightly -Zscript

//! ```cargo
//! [dependencies]
//! clap = "=4.3.22"
//! ```

fn main() {
    let _cmd = clap::Command::new("test")
        .args([
            clap::Arg::new("ignore-rust-version")
                .long("ignore-rust-version")
                .action(clap::ArgAction::SetTrue),
            clap::Arg::new("libtest-ignore")
                .long("ignored")
                .action(clap::ArgAction::SetTrue)
                .value_parser(
                    clap::builder::UnknownArgumentValueParser::suggest_arg("-- --ignored")
                        .and_suggest("not much else to say"),
                )
                .hide(true),
        ])
        .get_matches();
}

Steps to reproduce the bug with the above code

See above cargo script.

Actual Behaviour

$ cargo +nightly -Zscript clap-unknown-suggest-bug.rs

error: unexpected argument '--ignored' found

  tip: a similar argument exists: '-- --ignored'
  tip: not much else to say

Usage: clap-unknown-suggest-bug [OPTIONS]

For more information, try '--help'.

Expected Behaviour

Should not fail

Additional Context

cc #5075

Sorry I wasn't familiar with codebase enough to detect this bug during the review 😞.

Debug Output

No response

@epage
Copy link
Member

epage commented Aug 18, 2023

I had thought of this case but forgot it. The issue is we model a flag being present as a default_missing_value and not being present with default_value. In either case, we end up parsing a value.

A fix and new release will be available shortly

@weihanglo
Copy link
Author

Thanks a lot!

BTW, I feel the power of cargo-script 💪🏾.

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.

2 participants