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

Usage line is wrong in case of errors when using default values #774

Closed
dotdash opened this issue Dec 12, 2016 · 1 comment
Closed

Usage line is wrong in case of errors when using default values #774

dotdash opened this issue Dec 12, 2016 · 1 comment
Labels
C-enhancement Category: Raise on the bar on expectations
Milestone

Comments

@dotdash
Copy link
Contributor

dotdash commented Dec 12, 2016

Affected Version of clap

2.19.2

Expected Behavior Summary

The USAGE output is always the same, regardless of whether the user supplies --help or makes a usage error.

Actual Behavior Summary

Usage with --help:

USAGE:
    render <CONFIG> [ARGS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <CONFIG>    the configuration file
    <WIDTH>     texture width [default: 512]
    <HEIGHT>    texture height [default: 512]

Usage with a bad input:

error: The following required arguments were not provided:
    <CONFIG>

USAGE:
    render <CONFIG> <WIDTH> <HEIGHT>

For more information try --help

Note how <WIDTH> and <HEIGHT> are shown as required arguments.

Steps to Reproduce the issue

Call the executable created from the code below once with --help and once without any arguments.

Sample Code or Link to Sample Code

extern crate clap;
use clap::{Arg, App};

fn main() {
    let matches = App::new("My  app")
        .version("0.1")
        .author("Me <[email protected]>")
        .about("Does stuff")
        .arg(Arg::with_name("config")
             .value_name("CONFIG")
             .help("the configuration file")
             .required(true)
             .takes_value(true)
             .index(1))
        .arg(Arg::with_name("width")
             .value_name("WIDTH")
             .help("texture width")
             .takes_value(true)
             .default_value("512")
             .index(2))
        .arg(Arg::with_name("height")
             .value_name("HEIGHT")
             .help("texture height")
             .takes_value(true)
             .default_value("512")
             .index(3))
        .get_matches();
}
@kbknapp
Copy link
Member

kbknapp commented Dec 18, 2016

@dotdash apologies for the long time in answering this, I've been out of town for work.

In that usage line <width> and <height> are not shown as required arguments, they're shown as used arguments (a default is considered used). When clap detects an argument was used (required or not) it will inject those arguments into the usage string of errors. It's a manner of saying, "It seems like you were trying to do this... X ... but here's how you can correct it."

I agree this could be improved by not displaying arguments which only contain the default value. I can keep this on the issue tracker, but there are a few more pressing issues to fix first ;)

There's also the case of it'd be nice to inject the actual value the users used for those args (non-defaults only). I should be able to start knocking this out after the new year.

@kbknapp kbknapp added C: errors C-enhancement Category: Raise on the bar on expectations labels Dec 18, 2016
@kbknapp kbknapp added this to the 2.20.0 milestone Dec 27, 2016
@homu homu closed this as completed in 1f33de5 Jan 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Raise on the bar on expectations
Projects
None yet
Development

No branches or pull requests

2 participants