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

long_help() output includes output from long_version() instead of short_version() #3215

Closed
2 tasks done
ducaale opened this issue Dec 24, 2021 · 4 comments · Fixed by #3232
Closed
2 tasks done

long_help() output includes output from long_version() instead of short_version() #3215

ducaale opened this issue Dec 24, 2021 · 4 comments · Fixed by #3232
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-bug Category: Updating dependencies S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Milestone

Comments

@ducaale
Copy link
Contributor

ducaale commented Dec 24, 2021

Please complete the following tasks

  • I have searched the discussions
  • I have searched the existing issues

Rust Version

rustc 1.56.0 (09c42c458 2021-10-18)

Clap Version

3.0.0-rc.8

Minimal reproducible code

use clap::Parser;

fn long_version() -> &'static str {
    concat!(env!("CARGO_PKG_VERSION"), "\n", "+native-tls")
}

/// Simple program to greet a person
///
/// longer description
#[derive(Parser, Debug)]
#[clap(about, version, author, long_version = long_version())]
struct Args {
    /// Name of the person to greet
    #[clap(short, long)]
    name: String,

    /// Number of times to greet
    #[clap(short, long, default_value_t = 1)]
    count: u8,
}

fn main() {
    let args = Args::parse();

    for _ in 0..args.count {
        println!("Hello {}!", args.name)
    }
}

Steps to reproduce the bug with the above code

cargo run -- --help

Actual Behaviour

Help output includes +native-tls because it uses the output from --version rather than -V

temp-clap 0.1.0
+native-tls
Simple program to greet a person

longer description

USAGE:
    temp-clap [OPTIONS] --name <NAME>

OPTIONS:
    -c, --count <COUNT>
            Number of times to greet

            [default: 1]

    -h, --help
            Print help information

    -n, --name <NAME>
            Name of the person to greet

    -V, --version
            Print version information

Expected Behaviour

temp-clap 0.1.0
Simple program to greet a person

longer description

USAGE:
    temp-clap [OPTIONS] --name <NAME>

OPTIONS:
    -c, --count <COUNT>
            Number of times to greet

            [default: 1]

    -h, --help
            Print help information

    -n, --name <NAME>
            Name of the person to greet

    -V, --version
            Print version information

Additional Context

This bug only occurs when I set the long description for Clap. It happens every time the long help is outputted.

Debug Output

No response

@ducaale ducaale added the C-bug Category: Updating dependencies label Dec 24, 2021
@epage
Copy link
Member

epage commented Dec 24, 2021

Could you expand on why you consider it a bug for us to show the long version when we also show the long help?

@epage epage added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. A-help Area: documentation, including docs.rs, readme, examples, etc... labels Dec 24, 2021
@ducaale
Copy link
Contributor Author

ducaale commented Dec 24, 2021

Some CLI apps i.e ripgrep, include more output such as "enabled features" in the long version. And because Clap 2.x used the short version everywhere, there weren't any issues with that.

@ducaale ducaale changed the title Setting long description causes long_version() to be used in --help output long_version() to be used in long_help() output Dec 24, 2021
@ducaale ducaale changed the title long_version() to be used in long_help() output long_help() output includes output from long_version() instead of short_version() Dec 24, 2021
@epage
Copy link
Member

epage commented Dec 24, 2021

Ok, so this was a change of behavior from clap2 that you are concerned about.

Looks like this changed in #2369 without any direct acknowledgement (even says "version output is unchanged"). A reviewer did comment on it, just saying "Nice catch, adding a regression test would be great.".

@ldm0 any further background on why you were thinking its good for --help to show long version instead of the short version?

Still unsure of my thoughts. I wonder if this might be a case similar to #3193. In that, we only show short subcommand help, deferring to the subcommand's help for more details. Here, it might make sense for us to show the short version, deferring to the long version for more details.

@epage
Copy link
Member

epage commented Dec 27, 2021

@BurntSushi as someone who uses long-version, what are your thoughts on long help (--help) showing the long-version ("because its showing other long info", well, except subcommands) or showing the short version (delegating to --version)?

During clap3, --help was changed from showing the short version to showing the long version. There doesn't seem to have been any documented motivation behind the change. Trying to weigh out the different perspectives before making a decision.

@epage epage added this to the 3.0 milestone Dec 27, 2021
epage added a commit to epage/clap that referenced this issue Dec 30, 2021
When we got clap-rs#3193, we decided in clap-rs#3196 that `--help` will give a summary
for other commands (`subcmd --help` in this case) but not show the long
version of the output for that other command.

Now with clap-rs#3215, I think the case is similar for `--help` not showing the
long version but instead preferring the short version and encouraging
people to run `--version`.

Originally. clap only showed the short version or nothing.  This was
changed in clap-rs#2369 without fanfare to prefer the long version over short.
Now are we preferring short version over the long version always, just
like all other help.

Fixes clap-rs#3215
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 S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants