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

imp(errors): Provide the missing required arguments as info #2016

Merged
merged 1 commit into from
Jul 26, 2020
Merged

imp(errors): Provide the missing required arguments as info #2016

merged 1 commit into from
Jul 26, 2020

Conversation

nickelc
Copy link
Contributor

@nickelc nickelc commented Jul 15, 2020

Collect the missing required arguments for Error::info.

Code

use clap::clap_app;

fn main() {
    let app = clap_app!(prog =>
        (@arg arg1: +required)
        (@arg arg2: -o +required)
    );
    let m = app.try_get_matches();
    dbg!(m);
}

cargo r Output

[src/prog.rs:9] m = Err(
    Error {
        cause: "The following required arguments were not provided:\n    <arg1>\n    -o",
        message: error: The following required arguments were not provided:
            <arg1>
            -o
        
        USAGE:
            prog [FLAGS] <arg1> -o
        
        For more information try --help
        ,
        kind: MissingRequiredArgument,
        info: Some(
            [
                "<arg1>",
                "-o",
            ],
        ),
    },
)

@CreepySkeleton
Copy link
Contributor

Why do you need them?

@nickelc
Copy link
Contributor Author

nickelc commented Jul 15, 2020

Other error kinds provide info of wrong arguments, conflicts etc. MissingRequiredArgument is missing such info.

I want to use clap as command parser for a discord bot and I'll eventually generate the help & error messages

@CreepySkeleton
Copy link
Contributor

I asked because I want to remove the field entirely because I find it useless. For example, if you want to render the message, you can just err.to_string().

@pksunkara
Copy link
Member

It's not useless. We are providing some programmable information in that field as @nickelc said.

@pksunkara
Copy link
Member

@CreepySkeleton I gave the reasons in #1976. Let's go ahead and merge this one.

@CreepySkeleton CreepySkeleton mentioned this pull request Jul 19, 2020
@CreepySkeleton
Copy link
Contributor

hey @nickelc , could you please explain why exactly you need the names of the args? Why doesn't to_string suit you? We're having a dispute around this field, and your input would allow for more weighted decision.

@pksunkara
Copy link
Member

The error messages he wants to write is probably not the ones we are generating. And since .to_string() needs to be parsed to generate his custom message, he would much prefer and field in the error with the necessary related info.

@nickelc
Copy link
Contributor Author

nickelc commented Jul 20, 2020

I want to parse discord messages with clap but generate the help & error messages be myself as discord messages.

Maybe some kind of help & error renderer trait could help here to make clap more customizable.

@CreepySkeleton
Copy link
Contributor

I'm now convinced this can be useful, albeit seldom.

Maybe some kind of help & error renderer trait could help here to make clap more customizable.

If you have a solid idea, open a separate issue.

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 26, 2020

Build succeeded:

@bors bors bot merged commit dbdd63b into clap-rs:master Jul 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants