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

Error message quality regresssion from clap2 to clap3/4 #4379

Closed
2 tasks done
matklad opened this issue Oct 13, 2022 · 1 comment
Closed
2 tasks done

Error message quality regresssion from clap2 to clap3/4 #4379

matklad opened this issue Oct 13, 2022 · 1 comment
Labels
C-bug Category: Updating dependencies

Comments

@matklad
Copy link
Contributor

matklad commented Oct 13, 2022

Please complete the following tasks

Rust Version

rustc 1.64.0-beta.6 (25912c097 2022-09-09)

Clap Version

3.., 4..

Minimal reproducible code

// clap 2
use clap::{App, Arg, SubCommand};
fn main() {
    let matches = App::new("app")
        .arg(
            Arg::with_name("config")
                .short("c")
                .long("config")
                .value_name("FILE")
                .help("Sets a custom config file")
                .takes_value(true),
        )
        .subcommand(SubCommand::with_name("sub"))
        .get_matches();
    eprintln!("matches = {:?}", matches);
}

// clap 3
use clap::{App, Arg, SubCommand};
fn main() {
    let matches = App::new("app")
        .arg(
            Arg::with_name("config")
                .short('c')
                .long("config")
                .value_name("FILE")
                .help("Sets a custom config file")
                .takes_value(true),
        )
        .subcommand(SubCommand::with_name("sub"))
        .get_matches();
    eprintln!("matches = {:?}", matches);
}


// clap 4
use clap::{builder::{Arg, Command}, ArgAction};
fn main() {
    let matches = Command::new("app")
        .arg(
            Arg::new("config")
                .short('c')
                .long("config")
                .value_name("FILE")
                .help("Sets a custom config file")
                .action(ArgAction::Set),
        )
        .subcommand(Command::new("sub"))
        .get_matches();
    eprintln!("matches = {:?}", matches);
}

Steps to reproduce the bug with the above code

Run the above three binaries with sub -c foo args.

Clap2 gives correct, if not maximally helpful, error message:

error: Found argument '-c' which wasn't expected, or isn't valid in this context

USAGE:
    clap-repro sub

Clap3 and clap4 give actively misleading error messages:

error: Found argument '-c' which wasn't expected, or isn't valid in this context

	If you tried to supply `-c` as a value rather than a flag, use `-- -c`

USAGE:
    clap-repro sub
error: Found argument '-c' which wasn't expected, or isn't valid in this context

  If you tried to supply '-c' as a value rather than a flag, use '-- -c'

Usage: clap-repro sub

Actual Behaviour

Expected Behaviour

Additional Context

No response

Debug Output

No response

@epage
Copy link
Member

epage commented Oct 13, 2022

This looks to be a duplicate of #2766. If I misunderstood, let me know and I can re-open this.

In #2766 could you clarify what you are not liking and why it caused confusion about the CLI in near/nearcore#7732?

@epage epage closed this as completed Oct 13, 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