Skip to content

Detect if --help was likely intended for binary being run #9707

@pnkfelix

Description

@pnkfelix

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 than cargo 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 for cargo 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:

  1. cargo run --help could include both the --help for cargo run itself, and also run the binary passing --help to it

The 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:

  1. 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 do cargo run -- --help

Likewise, cargo run --bin program --help would include a line suggesting cargo run --bin program -- --help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cliArea: Command-line interface, option parsing, etc.C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions