-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Subcommand bin_name on Windows contains ".exe" in the middle instead of at the end (or not at all) #992
Comments
Just stripping Of course this will lead to the wrong output from |
When building the subcommand name, I'd be fine with stripping the |
To avoid issues with whether the shell included the |
Are there safe bindings to it? |
Actually, it turns out |
Will you be sending a PR? |
It's actually more complicated than it sounds. With
Which one to choose? Do we just discard the element and use |
What are the reasons for using |
The iterator
|
The purpose of that setting was to start parsing immediately as arguments, instead of skipping
That's the incorrect bit 😉 clap assumes the binary name was set manually when |
This comment has been minimized.
This comment has been minimized.
We've also run into this when testing examples, like the former
|
Why would we not just strip |
I am under the impression that we do. bin name has always been about the actual binary name and I think it's been used in other places with that assumption which is why Kevin suggested a new variable to hold this name in the first place.
If you were to audit the usage of it and decide that it's okay setting bin name without |
Looking around, it looks like its only used for display purposes, like help and error messages. I'm not seeing anything doing processing based on the name. We don't expose the let matches = app.get_matches_mut();
let bin = app.get_bin_name() Personally, that feels hacky; imo all parse results should be coming from |
Are you asking if |
This is a step towards clap-rs#992. When help renders the application name, it uses the `bin` template variable which is just the `bin` name with spaces converted to ` `. While having `app.exe sub` makes sense, `app.exe-sub` does not. To get around needing this for usage, we've created a `display_name` field that is fairly similar but - The root name is the `name` and not `bin_name` - We always join with `-` This means that the derived `bin_name` will only show up in usage. For now, the default template has not been updated as that is a minor compatibility change and should be in a minor release, at least.
This is a step towards clap-rs#992. When help renders the application name, it uses the `bin` template variable which is just the `bin` name with spaces converted to ` `. While having `app.exe sub` makes sense, `app.exe-sub` does not. To get around needing this for usage, we've created a `display_name` field that is fairly similar but - The root name is the `name` and not `bin_name` - We always join with `-` This means that the derived `bin_name` will only show up in usage. For now, the default template has not been updated as that is a minor compatibility change and should be in a minor release, at least. I was worried this would be a full breaking change. The main case I was worried about was cargo subcommands but our tests show they should just work.
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 |
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
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
(I am using clap 3.2.14) [[bin]]
name = "app_name"
path = "src/main.rs" and a struct using clap: #[derive(Parser, Debug, PartialEq, Eq, Deserialize, Default)]
#[clap(version, setting(clap::AppSettings::DeriveDisplayOrder))]
pub struct MyStruct {
...
} after running
I do can eliminate the #[clap(bin_name = "app_name", version, setting(clap::AppSettings::DeriveDisplayOrder))] But is there a way without changing the derivative macro? Meanwhile, I also wonder how to output like so:
with |
Specifying attributes is how you customize clap via the derive and setting
|
Rust Version
rustc 1.20.0-nightly (f590a44ce 2017-06-27)
Affected Version of clap
2.25.0
Steps to Reproduce the issue
Cargo.toml
:src/main.rs
:cargo run -- bar --help
(This runstarget\debug\foo.exe bar --help
. Note the.exe
). Alternatively, run.\target\debug\foo.exe bar --help
in cmd or PS. Both these will setargv[0]
to something ending withfoo.exe
Also, running
.\target\debug\foo bar --help
in PS (note doesn't have.exe
) will still haveargv[0]
ending withfoo.exe
because PS adds it automatically when spawning the process. cmd does not have this behavior so.\target\debug\foo bar --help
in cmd will haveargv[0]
ending infoo
Expected Behavior Summary
Output should say
foo-bar
orfoo-bar.exe
as the name above the usage.Actual Behavior Summary
Output says
foo.exe-bar
as the name above the usage. Note that the usage itself printsfoo.exe bar
which is fine, just the name printed above the usage is the problem.Debug output
The
debug
feature does not build on Windows.Workaround
Provide the
bin_name
manually instead of letting clap parse it fromstd::env::args_os()
.The text was updated successfully, but these errors were encountered: