epage / clapng

A full featured, fast Command Line Argument Parser for Rust
docs.rs/clap
Apache License 2.0
0 stars 0 forks source link

Allow to show less verbose messages or avoid unsupported suggestions #206

Open epage opened 2 years ago

epage commented 2 years ago

Issue by silvioprog Thursday Sep 09, 2021 at 18:54 GMT Originally opened as https://github.com/clap-rs/clap/issues/2766


Please complete the following tasks

Clap Version

3.0.0-beta.4

Describe your use case

Hi.

Assuming I have an args.rs file:

use clap::Clap;

#[derive(Debug, Clap)]
pub struct Args {
    #[clap(short)]
    pub metric: bool,
    #[clap(short)]
    pub imperial: bool,
}

and a main.rs:

use clap::Clap;

mod args;

fn main() {
    let args = args::Args::parse();
    println!("{:?}", args);
}

if I call the executable like this (passing an invalid flag):

./target/debug/teste -d

it returns this message:

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

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

USAGE:
    teste [FLAGS]

For more information try --help

Describe the solution you'd like

It would be nice any global configuration in Clap to avoid suggestions like -- -x. The message would be like this, which is much clear for the user (since the application contains only two optional flags):

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

USAGE:
    teste [FLAGS]

For more information try --help

or:

error: Found argument '-d' which wasn't expected, or isn't valid

USAGE:
    teste [FLAGS]

For more information try --help

or even:

error: Found argument '-d' which isn't valid

USAGE:
    teste [FLAGS]

For more information try --help

Alternatives, if applicable

No response

Additional Context

No response

epage commented 2 years ago

Comment by pksunkara Thursday Sep 09, 2021 at 19:02 GMT


@ldm0 Can we skip that if the subcommand we are parsing doesn't have any args with multiple values?