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

Display help menu if user provides an unknow option #7122

Closed
tcharding opened this issue Jul 11, 2019 · 3 comments
Closed

Display help menu if user provides an unknow option #7122

tcharding opened this issue Jul 11, 2019 · 3 comments
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`

Comments

@tcharding
Copy link
Contributor

Describe the problem you are trying to solve

Entering an unknown option to cargo causes cargo to return an error message stating that the option is unknown and directing the user to try cargo --help. This is not super useful because if the user entered an incorrect option typically the user will want/need to see the help menu. We force the user to enter a second command to see the help menu.

$ cargo build --does-not-exist
error: Found argument '--does-not-exist' which wasn't expected, or isn't valid in this context

USAGE:
    cargo build [OPTIONS]

For more information try --help

Describe the solution you'd like

We can improve the user experience by just displaying the help menu for unknown options. This has the added advantage that miss typing --help still shows the help menu.

Notes

I may be the only one that miss-types --help when rapidly hacking on stuff but I doubt it :)

@tcharding tcharding added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Jul 11, 2019
@tcharding
Copy link
Contributor Author

Oh, is this to do with the Rust library used to create the CLI. Perhaps this issue should be moved there?

@ehuss ehuss added the A-cli Area: Command-line interface, option parsing, etc. label Sep 21, 2019
@epage
Copy link
Contributor

epage commented Nov 1, 2023

The CLI will suggest an alternative if the unknown-option is likely a typo.

We also did #11702 so commonly used arguments in other build tools would provide direct people with what flag to use in cargo.

Personally, I find it annoying when a CLI outputs the help on error. Take git as an example

$ git checkout --kljljkljlkj
error: unknown option `kljljkljlkj'
usage: git checkout [<options>] <branch>
   or: git checkout [<options>] [<branch>] -- <file>...
                                                                                                                      
    -b <branch>           create and checkout a new branch
    -B <branch>           create/reset and checkout a branch
    -l                    create reflog for new branch
    --guess               second guess 'git checkout <no-such-branch>' (default)
    --overlay             use overlay mode (default)
    -q, --quiet           suppress progress reporting
    --recurse-submodules[=<checkout>]
                          control recursive updating of submodules
    --progress            force progress reporting
    -m, --merge           perform a 3-way merge with the new branch
    --conflict <style>    conflict style (merge or diff3)
    -d, --detach          detach HEAD at named commit
    -t, --track           set upstream info for new branch
    -f, --force           force checkout (throw away local modifications)
    --orphan <new-branch>
                          new unparented branch
    --overwrite-ignore    update ignored files (default)
    --ignore-other-worktrees
                          do not check if another worktree is holding the given ref
    -2, --ours            checkout our version for unmerged files
    -3, --theirs          checkout their version for unmerged files
    -p, --patch           select hunks interactively
    --ignore-skip-worktree-bits
                          do not limit pathspecs to sparse entries only
    --pathspec-from-file <file>
                          read pathspec from file
    --pathspec-file-nul   with --pathspec-from-file, pathspec elements are separated with NUL character

The actual error message can easily be lost in the help output.

Now apply that to something like cargo check which has this for its "short" help:

$ cargo check -h
Check a local package and all of its dependencies for errors
                                                                                                                      
Usage: cargo check [OPTIONS]
                                                                                                                      
Options:
      --ignore-rust-version     Ignore `rust-version` specification in packages
      --future-incompat-report  Outputs a future incompatibility report at the end of the build
      --message-format <FMT>    Error format
  -q, --quiet                   Do not print cargo log messages
  -v, --verbose...              Use verbose output (-vv very verbose/build.rs output)
      --color <WHEN>            Coloring: auto, always, never
      --config <KEY=VALUE>      Override a configuration value
  -Z <FLAG>                     Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
  -h, --help                    Print help
                                                                                                                      
Package Selection:
  -p, --package [<SPEC>]  Package(s) to check
      --workspace         Check all packages in the workspace
      --exclude <SPEC>    Exclude packages from the check
      --all               Alias for --workspace (deprecated)
                                                                                                                      
Target Selection:
      --lib               Check only this package's library
      --bins              Check all binaries
      --bin [<NAME>]      Check only the specified binary
      --examples          Check all examples
      --example [<NAME>]  Check only the specified example
      --tests             Check all tests
      --test [<NAME>]     Check only the specified test target
      --benches           Check all benches
      --bench [<NAME>]    Check only the specified bench target
      --all-targets       Check all targets
                                                                                                                      
Feature Selection:
  -F, --features <FEATURES>  Space or comma separated list of features to activate
      --all-features         Activate all available features
      --no-default-features  Do not activate the `default` feature
                                                                                                                      
Compilation Options:
  -j, --jobs <N>                Number of parallel jobs, defaults to # of CPUs.
      --keep-going              Do not abort the build as soon as there is an error (unstable)
  -r, --release                 Check artifacts in release mode, with optimizations
      --profile <PROFILE-NAME>  Check artifacts with the specified profile
      --target <TRIPLE>         Check for the target triple
      --target-dir <DIRECTORY>  Directory for all generated artifacts
      --unit-graph              Output build graph in JSON (unstable)
      --timings[=<FMTS>]        Timing output formats (unstable) (comma separated): html, json
                                                                                                                      
Manifest Options:
      --manifest-path <PATH>  Path to Cargo.toml
      --frozen                Require Cargo.lock and cache are up to date
      --locked                Require Cargo.lock is up to date
      --offline               Run without accessing the network
                                                                                                                      
Run `cargo help check` for more detailed information.

That can easily scroll off the screen.

Looking back at this output, I feel like "the cure" would be worse than the problem and am going to close this. If there is a reason we should re-evaluate this, let us know!

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2023
@tcharding
Copy link
Contributor Author

All fair points, thanks mate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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`
Projects
None yet
Development

No branches or pull requests

3 participants