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 message is misleading when SubcommandsNegateReqs is used #871

Closed
malbarbo opened this issue Feb 22, 2017 · 2 comments
Closed

Usage message is misleading when SubcommandsNegateReqs is used #871

malbarbo opened this issue Feb 22, 2017 · 2 comments
Labels
C-bug Category: Updating dependencies
Milestone

Comments

@malbarbo
Copy link
Contributor

Affected Version of clap

2.20.5

Expected Behavior Summary

Show a usage message that is more accurate, like

USAGE:
    16_app_settings (<input> | SUBCOMMAND)

or

USAGE:
    16_app_settings <input>
    16_app_settings SUBCOMMAND

With flags it become more difficult to write a usage message...

Actual Behavior Summary

Show a usage message that is misleading

myapp 

USAGE:
    16_app_settings <input> [SUBCOMMAND]

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

ARGS:
    <input>    input file to use

SUBCOMMANDS:
    help    Prints this message or the help of the given subcommand(s)
    test    does some testing

This suggests that a subcommand can be used after <input> but it cannot.

Steps to Reproduce the issue

cargo run --example 16_app_settings -- -h
@kbknapp
Copy link
Member

kbknapp commented Feb 22, 2017

Good catch, I agree. I tend to like the dual line usage, but that may be slightly harder to implement in current clap. I'll play with it and see.

@kbknapp kbknapp added C: settings C-bug Category: Updating dependencies labels Feb 22, 2017
@kbknapp kbknapp added this to the 2.20.6 milestone Feb 22, 2017
@wfraser
Copy link

wfraser commented Feb 25, 2017

I noticed that in addition to showing the arg in the help for the main command, it also shows it in the help for the subcommand, but DOES NOT show it if you give a value for it. Really weird.

I.e.:

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

fn main() {
    let args = clap::App::new("")
        .arg(Arg::with_name("input")
            .required(true)
            .help("the input"))
        .subcommand(SubCommand::new("test"))
        .get_matches();

    println!("{:#?}", args);
}
$ cargo run -- --help
   Compiling clap-experiments v0.1.0 (file:///D:/code/clap-experiments)
    Finished dev [unoptimized + debuginfo] target(s) in 1.22 secs
     Running `target\debug\clap-experiments.exe --help`


USAGE:
    clap-experiments.exe <input> [SUBCOMMAND]

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

ARGS:
    <input>    the input

SUBCOMMANDS:
    help    Prints this message or the help of the given subcommand(s)
    test
$ cargo run -- test --help
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target\debug\clap-experiments.exe test --help`
clap-experiments.exe-test

USAGE:
    clap-experiments.exe <input> test

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information
$ cargo run -- foo test --help
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target\debug\clap-experiments.exe foo test --help`
clap-experiments.exe-test

USAGE:
    clap-experiments.exe test

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

Note how in the last example, the <input> parameter is gone from the help text.

kbknapp added a commit that referenced this issue Mar 9, 2017
…s are used, a new more accurate double line usage string is shown

Closes #871
kbknapp added a commit that referenced this issue Mar 9, 2017
…s are used, a new more accurate double line usage string is shown

Closes #871
@homu homu closed this as completed in c8ab24b Mar 11, 2017
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

3 participants