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

Help message prints argument name twice if no value name was given #472

Closed
klingtnet opened this issue Apr 1, 2016 · 3 comments
Closed
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-bug Category: Updating dependencies

Comments

@klingtnet
Copy link

Argument names are printed as values in the help message if no value_name of value_names was given for the CLI argument. The problem is located in src/args/help_writer.rs line 117. I tried to replace the line with: try!(write!(w, "<{}>", self.a.name())); but this breaks some other tests.
If no value_name was set the long or short argument name is printed twice before the arguments value.

extern crate clap;

fn main() {
    let addr = clap::Arg::with_name("address")
                   .long("address")
                   .short("a")
                   .takes_value(true)
                   .default_value("0.0.0.0")
                   .group("osc")
                   .help("Address to listen on for OSC messages.");
    let sr = clap::Arg::with_name("sample-rate")
                 .long("sample-rate")
                 .short("s")
                 .takes_value(true)
                 .default_value("48000")
                 .possible_values(&["44100", "48000", "88200", "96000"])
                 .help("Playback sample-rate");
    let ports = clap::Arg::with_name("ports")
                    .long("ports")
                    .short("p")
                    .required(true)
                    .takes_value(true)
                    .number_of_values(2)
                    .value_names(&["in", "out"])
                    .group("osc")
                    .help("OSC listening and send port.");
    let args = clap::App::new("ytterbium")
                   .version("0.1.0")
                   .author("Andreas Linz <[email protected]>")
                   .arg(addr)
                   .arg(ports)
                   .arg(sr);
    let mut buf: Vec<u8> = Vec::with_capacity(128);
    let mut out = ::std::io::stdout();
    args.write_help(&mut out);
}

This prints the following help message:

ytterbium 0.1.0
Andreas Linz <[email protected]>

USAGE:
    ytterbium [FLAGS] [OPTIONS] --ports <in> <out>

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

OPTIONS:
    -a, --address --address <address>            Address to listen on for OSC messages. [default: 0.0.0.0] 
    -p, --ports <in> <out>             OSC listening and send port.
    -s, --sample-rate --sample-rate <sample-rate>    Playback sample-rate [default: 48000]  [values: 44100, 48000, 88200, 96000]

If you look at the OPTIONS you can see that --address is printed twice as well as --sample-rate.
Adding value_names fixes the problem:

    let addr = clap::Arg::with_name("address")
// ...
                   .takes_value(true)
                   .value_name("ip-address")
// ...
    let sr = clap::Arg::with_name("sample-rate")
// ...
                 .takes_value(true)
                 .value_name("sample-rate")
// ...
...
OPTIONS:
    -a, --address <ip-address>         Address to listen on for OSC messages. [default: 0.0.0.0] 
    -p, --ports <in> <out>             OSC listening and send port.
    -s, --sample-rate <sample-rate>    Playback sample-rate [default: 48000]  [values: 44100, 48000, 88200, 96000]

If this is intended behavior then please add a note in the documentation that setting value_names is mandatory for arguments that takes_value.

@kbknapp kbknapp added C-bug Category: Updating dependencies P1: urgent A-help Area: documentation, including docs.rs, readme, examples, etc... labels Apr 3, 2016
@kbknapp
Copy link
Member

kbknapp commented Apr 3, 2016

This is a bug, thanks for pointing it out! I'll get it fixed real quick and put out the updated version. Thanks!

@kbknapp
Copy link
Member

kbknapp commented Apr 3, 2016

Once #474 merges I'll put out the new version on crates.io

@klingtnet
Copy link
Author

Thank you for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-bug Category: Updating dependencies
Projects
None yet
Development

No branches or pull requests

2 participants