clap
clap copied to clipboard
The command name should default to CARGO_BIN_NAME
Please complete the following tasks
- [X] I have searched the discussions
- [X] I have searched the open and rejected issues
Clap Version
4.5.9
Describe your use case
I want the default -V / --version to use the binary name instead of the package name, because this is the name users are familiar with. This situation happens when a project has both a library and a CLI. The CLI usually provides a binary with a different name than the package.
The documentation says that the magic command attribute name defaults to the package name on Parser. I wonder if this was decided before CARGO_BIN_NAME was a thing, or if it's just an oversight, or if there is a good reason to do so.
Describe the solution you'd like
I'd like the default name to be CARGO_BIN_NAME instead of CARGO_PKG_NAME.
Alternatives, if applicable
The obvious workaround is to specify a command name. This is completely fine, but the default is in my opinion wrong, so I'm creating an issue to understand the rationale.
Additional Context
No response
Note that this would be a breaking change and wouild have to wait until clap v5, at least.
It would be good to sample various clap projects to see how package.name and bin.name might vary between them to see if there would be any unintended affect.
Note that this would be a breaking change and wouild have to wait until clap v5, at least.
Yes, makes sense.
It would be good to sample various clap projects to see how
package.nameandbin.namemight vary between them to see if there would be any unintended affect.
Yes, I'm also curious. I quickly looked at the top 20 reverse dependencies of clap and used the new "Install" feature of crates.io to identify those with a binary and the name of the binary too:
| package | binary | notes |
|---|---|---|
addr2line |
addr2line |
|
remove_dir_all |
remove-dir-all |
for some reason, --version shows the binary name |
cbindgen |
cbindgen |
|
raw-cpuid |
cpuid |
affected by this issue, see https://github.com/gz/rust-cpuid/issues/189 |
dotenvy |
dotenvy |
|
dotenv |
dotenv |
So it seems to not affect that many crates on such a small sample.