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

bin_name overrides name in the help message #1474

Closed
sphynx opened this issue May 20, 2019 · 5 comments · Fixed by #3693
Closed

bin_name overrides name in the help message #1474

sphynx opened this issue May 20, 2019 · 5 comments · Fixed by #3693
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations 💸 $5 S-triage Status: New; needs maintainer attention.
Milestone

Comments

@sphynx
Copy link
Contributor

sphynx commented May 20, 2019

Maintainer's notes


Rust Version

rustc 1.36.0-nightly (af98304b9 2019-05-11)

Affected Version of clap

2.33

Bug or Feature Request Summary

If I use bin_name to override executable name in usage (for something like cargo command), clap also automatically overrides name (as well as argument to App::new) in the help message. It would be nice to have control over the name, since it appears at the very top of the help message.

Expected Behavior Summary

> cargo run -- --help
appname

USAGE:
    bin name

Actual Behavior Summary

> cargo run -- --help
bin-name

USAGE:
    bin name

Steps to Reproduce the issue

cargo run -- --help

Sample Code or Link to Sample Code

use clap::App;

fn main() {
    App::new("My Super Program")
        .name("appname")
        .bin_name("bin name")
        .get_matches();
}

Debug output

Debug Output

DEBUG:clap:Parser::propagate_settings: self=appname, g_settings=AppFlags(
(empty),
)
DEBUG:clap:Parser::get_matches_with;
DEBUG:clap:Parser::create_help_and_version;
DEBUG:clap:Parser::create_help_and_version: Building --help
DEBUG:clap:Parser::create_help_and_version: Building --version
DEBUG:clap:Parser::get_matches_with: Begin parsing '"--help"' ([45, 45, 104, 101, 108, 112])
DEBUG:clap:Parser::is_new_arg:"--help":NotFound
DEBUG:clap:Parser::is_new_arg: arg_allows_tac=false
DEBUG:clap:Parser::is_new_arg: -- found
DEBUG:clap:Parser::is_new_arg: starts_new_arg=true
DEBUG:clap:Parser::possible_subcommand: arg="--help"
DEBUG:clap:Parser::get_matches_with: possible_sc=false, sc=None
DEBUG:clap:ArgMatcher::process_arg_overrides:None;
DEBUG:clap:Parser::parse_long_arg;
DEBUG:clap:Parser::parse_long_arg: Does it contain '='...No
DEBUG:clap:Parser::parse_long_arg: Found valid flag '--help'
DEBUG:clap:Parser::check_for_help_and_version_str;
DEBUG:clap:Parser::check_for_help_and_version_str: Checking if --help is help or version...Help
DEBUG:clap:Parser::_help: use_long=true
DEBUG:clap:Help::write_parser_help;
DEBUG:clap:Help::write_parser_help;
DEBUG:clap:Parser::color;
DEBUG:clap:Parser::color: Color setting...Auto
DEBUG:clap:is_a_tty: stderr=false
DEBUG:clap:Help::new;
DEBUG:clap:Help::write_help;
DEBUG:clap:Help::write_default_help;
DEBUG:clap:Help::write_bin_name;
DEBUG:clap:Help::write_version;
DEBUG:clap:usage::create_usage_no_title;
DEBUG:clap:usage::get_required_usage_from: reqs=[], extra=None
DEBUG:clap:usage::get_required_usage_from: after init desc_reqs=[]
DEBUG:clap:usage::get_required_usage_from: no more children
DEBUG:clap:usage::get_required_usage_from: final desc_reqs=[]
DEBUG:clap:usage::get_required_usage_from: args_in_groups=[]
DEBUG:clap:usage::needs_flags_tag;
DEBUG:clap:usage::needs_flags_tag:iter: f=hclap_help;
DEBUG:clap:usage::needs_flags_tag:iter: f=vclap_version;
DEBUG:clap:usage::needs_flags_tag: [FLAGS] not required
DEBUG:clap:usage::create_help_usage: usage=bin name
DEBUG:clap:Help::write_all_args;
DEBUG:clap:Help::write_args;
DEBUG:clap:Help::write_args: Current Longest...2
DEBUG:clap:Help::write_args: New Longest...6
DEBUG:clap:Help::write_args: Current Longest...6
DEBUG:clap:Help::write_args: New Longest...9
DEBUG:clap:Help::write_arg;
DEBUG:clap:Help::short;
DEBUG:clap:Help::long;
DEBUG:clap:Help::val: arg=--help
DEBUG:clap:Help::spec_vals: a=--help
DEBUG:clap:Help::val: Has switch...Yes
DEBUG:clap:Help::val: force_next_line...false
DEBUG:clap:Help::val: nlh...false
DEBUG:clap:Help::val: taken...21
DEBUG:clap:Help::val: help_width > (width - taken)...23 > (120 - 21)
DEBUG:clap:Help::val: longest...9
DEBUG:clap:Help::val: next_line...No
DEBUG:clap:write_spaces!: num=7
DEBUG:clap:Help::help;
DEBUG:clap:Help::help: Next Line...false
DEBUG:clap:Help::help: Too long...No
DEBUG:clap:Help::write_arg;
DEBUG:clap:Help::short;
DEBUG:clap:Help::long;
DEBUG:clap:Help::val: arg=--version
DEBUG:clap:Help::spec_vals: a=--version
DEBUG:clap:Help::val: Has switch...Yes
DEBUG:clap:Help::val: force_next_line...false
DEBUG:clap:Help::val: nlh...false
DEBUG:clap:Help::val: taken...21
DEBUG:clap:Help::val: help_width > (width - taken)...26 > (120 - 21)
DEBUG:clap:Help::val: longest...9
DEBUG:clap:Help::val: next_line...No
DEBUG:clap:write_spaces!: num=4
DEBUG:clap:Help::help;
DEBUG:clap:Help::help: Next Line...false
DEBUG:clap:Help::help: Too long...No
bin-name

USAGE:
bin name

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

@CreepySkeleton CreepySkeleton added A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations W: 2.x S-waiting-on-decision Status: Waiting on a go/no-go before implementing labels Feb 1, 2020
@Wtoll
Copy link

Wtoll commented Sep 8, 2020

I second this being a necessary addition. I'm trying to write an extension to cargo (cargo-extension binary name as an example), and in order to have the usage information make sense, the bin name has to be set to "cargo extension", but then that forces the name in the version write out to be "cargo-extension" which is not very descriptive or helpful.

Considering cargo itself uses clap I think it makes sense for clap to be fully able to support writing extensions to cargo, and part of that includes allowing the "name" field to take precedence over the "bin-name" field to allow for both an accurate usage example, and a descriptive name.

Also, because I noticed the version number in this issue is different, this also equally affects clap v3.0.0-beta.1 which is what I've been developing with.

@pksunkara pksunkara removed W: 2.x S-waiting-on-decision Status: Waiting on a go/no-go before implementing labels Oct 5, 2020
@pksunkara pksunkara added this to the 3.1 milestone Oct 5, 2020
@pksunkara
Copy link
Member

Note: Need to check if NoBinaryName solves it.

@epage epage added the S-triage Status: New; needs maintainer attention. label Dec 9, 2021
@epage epage removed this from the 3.1 milestone Dec 9, 2021
@epage
Copy link
Member

epage commented Dec 14, 2021

From a comment of mine in #3096

From help2man's docs

Use argv[0] for the program name in these synopses, just as it is, with no directory stripping. This is in contrast to the canonical (constant) name of the program which is used in --version.

Interesting. They want the usage to use argv[0] but everywhere else to the use actual name.

For us, we show the bin name as the application name (see #992). Our bin name is argv[0].file_name() though with #992 I am considering changing it to argv[0].file_stem() or similar.

@epage
Copy link
Member

epage commented May 4, 2022

#3680 added a help_template variable for this. I'm debating whether it can be the default in 3.2 (minor compatibility break) or 4.0 (major compatibility break).

This is also helping #992

@epage epage added this to the 3.2 milestone May 4, 2022
@epage epage modified the milestones: 3.2, 4.0 May 5, 2022
@epage
Copy link
Member

epage commented May 5, 2022

We're close enough to when we can start working on 4.0, I'm going to play it safe and push it off to then

epage added a commit to epage/clap that referenced this issue May 5, 2022
This will mean we won't have an awkard `.exe` in the middle on Windows

This means users can have a display name for their application rather
than it being dependent on the binary name it was run as

This means users can manually set it to use spaces instead of dashes for
separating things out.

Fixes clap-rs#992
Fixes clap-rs#1474
Fixes clap-rs#1431
epage added a commit to epage/clap that referenced this issue May 5, 2022
This will mean we won't have an awkard `.exe` in the middle on Windows

This means users can have a display name for their application rather
than it being dependent on the binary name it was run as

This means users can manually set it to use spaces instead of dashes for
separating things out.

Fixes clap-rs#992
Fixes clap-rs#1474
Fixes clap-rs#1431
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-enhancement Category: Raise on the bar on expectations 💸 $5 S-triage Status: New; needs maintainer attention.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants