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

Overriding --help produces a different message than the default #536

Closed
brianp opened this issue Jun 23, 2016 · 1 comment
Closed

Overriding --help produces a different message than the default #536

brianp opened this issue Jun 23, 2016 · 1 comment
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-bug Category: Updating dependencies
Milestone

Comments

@brianp
Copy link
Contributor

brianp commented Jun 23, 2016

When overriding the help flag using long("help"), the auto-generated help output is different from the default.

Differences include:

  • The app bin_name in the usage example
  • No version flag is displayed

Example app, with expected default output:

fn main() {
    let app = App::new("test").get_matches();
}

Output:

$ cargo run -- --help
     Running `target/debug/clapapp --help`
test

USAGE:
    clapapp [FLAGS]

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

Example app overriding help, and different output:

fn main() {
    let app = App::new("test")
                  .arg(Arg::with_name("help")
                       .short("h")
                       .long("help")
                       .help("Prints help information")
                       .takes_value(false));

    let matches = &app.clone().get_matches();

    if matches.is_present("help") {
        let _ = &app.print_help();
        println!("\n");
    };
}

Output:

$ cargo run -- --help
     Running `target/debug/clapapp --help`
test

USAGE:
    test [FLAGS]

FLAGS:
    -h, --help    Prints help information
@kbknapp kbknapp added this to the 2.7.0 milestone Jun 23, 2016
@kbknapp kbknapp added C-bug Category: Updating dependencies P2: need to have A-help Area: documentation, including docs.rs, readme, examples, etc... labels Jun 23, 2016
@kbknapp
Copy link
Member

kbknapp commented Jun 23, 2016

I'm on mobile so I can't give a good link at the moment, but if you look at line 460 of src/app/parser.rs you'll see a call to build_help_and_version which never gets called when print_help is called.

Simply inserting that call will fix it, but also have the side effect that it's called twice on a normal run. So we either need to find a way to not call it twice, minimize the runtime impact if it is called twice, or something to the like.

Something that might help is use the Parser::is_set methods to check the internal AppSettings for things like NeedsLongHelp (or Version) instead of iterating all flags.

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