Detect if --help
was likely intended for binary being run
#9707
Labels
A-cli
Area: Command-line interface, option parsing, etc.
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Describe the problem you are trying to solve
When I invoke
cargo run --bin program --help
, sometimes I intended for the--help
to be passed to the program I am invoking, rather thancargo
itself.Right now, the above invocation spits out the same information that you get when you do
cargo run --help
.The information emitted does include the command syntax:
cargo run [OPTIONS] [--] [args]...
But it doesn't provide guidance specifically saying that I might have intended to feed in the
--help
as part of the[args]...
Describe the solution you'd like
In an ideal world,
cargo
would read my mind and figure out whether the--help
is intended forcargo
itself, or for the program I'm running, and only pass it to whichever I intended. Of course its not realistic, but it does spell out one ambitious option:cargo run --help
could include both the--help
forcargo run
itself, and also run the binary passing--help
to itThe main problem with that option is that running the binary may have side-effects that one would never intend from invoking
cargo run --help
. For that, I'd suggest running the binary in a sandbox: no file-writes, no network traffic.Still, that approach may be a lot of work for an approach that still might be a minefield.
So here is a more conservative option:
cargo run --help
could explicitly point out how to adjust the command line to pass--help
to the underlying binary.So,
cargo run --help
would also include a line suggesting that one might docargo run -- --help
Likewise,
cargo run --bin program --help
would include a line suggestingcargo run --bin program -- --help
.The text was updated successfully, but these errors were encountered: