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

feat: show truncated help on some errors #1004

Merged
merged 3 commits into from
Mar 12, 2024

Conversation

mdonnalley
Copy link
Contributor

@mdonnalley mdonnalley commented Mar 7, 2024

  • Show USAGE, FLAGS, and ARGUMENTS on Unexpected argument, Nonexistent flag, and Required arg errors
❯ bin/run.js hello world --DOES_NOT_EXIST
 ›   Error: Nonexistent flag: --DOES_NOT_EXIST
 ›   See more help with --help

USAGE
  $ oex hello world [--flag1 <value>]

FLAGS
  --flag1=<value>
  • Adds sections and sendToStderr options to HelpOptions
    • Setting sections allows users to select which help sections they want printed. If undefined, it will show all sections.
    • Setting sendToStderr will send all help output to stderr instead of stdout
  • Moves error and warn functions into separate files so we can avoid circular imports

Fixes #679

@W-15103729@

@cristiand391
Copy link
Member

tested with plugin-plugins and some changes to make args required:

missing required arg

./bin/run.js plugins inspect, with arg requred=true:

➜  plugin-plugins git:(main) ✗ ./bin/run.js plugins inspect
 ›   Error: Missing 1 required arg:
 ›   plugin  Plugin to inspect.
 ›   See more help with --help

USAGE
  $ mycli plugins inspect PLUGIN...

ARGUMENTS
  PLUGIN  Plugin to inspect.

FLAGS
  -h, --help     Show CLI help.
  -v, --verbose

GLOBAL FLAGS
  --json  Format output as json.

unknown flag

➜  plugin-plugins git:(main) ✗ ./bin/run.js plugins inspect data --asfd
 ›   Error: Nonexistent flag: --asfd
 ›   See more help with --help

USAGE
  $ mycli plugins inspect PLUGIN...

ARGUMENTS
  PLUGIN  Plugin to inspect.

FLAGS
  -h, --help     Show CLI help.
  -v, --verbose

GLOBAL FLAGS
  --json  Format output as json.

unexpected arg:

➜  plugin-plugins git:(main) ✗ ./bin/run.js plugins link test toast
 ›   Error: Unexpected argument: toast
 ›   See more help with --help

USAGE
  $ mycli plugins link PLUGIN

ARGUMENTS
  PATH  [default: .] path to plugin

FLAGS
  -h, --help          Show CLI help.
  -v, --verbose
      --[no-]install  Install dependencies after linking the plugin.

help is sent to stderr:

./bin/run.js plugins inspect 2> stderr.txt

➜  plugin-plugins git:(main) ✗ cat stderr.txt
 ›   Error: Missing 1 required arg:
 ›   plugin  Plugin to inspect.
 ›   See more help with --help

USAGE
  $ mycli plugins inspect PLUGIN...

ARGUMENTS
...

@cristiand391 cristiand391 merged commit 7133a97 into main Mar 12, 2024
79 checks passed
@cristiand391 cristiand391 deleted the mdonnalley/show-help-on-error branch March 12, 2024 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Print valid command/flags when passing in an invalid value
2 participants