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

cli: fix help message #9842

Merged
merged 6 commits into from
Aug 10, 2021
Merged

cli: fix help message #9842

merged 6 commits into from
Aug 10, 2021

Conversation

paul-marechal
Copy link
Member

@paul-marechal paul-marechal commented Aug 4, 2021

The CLI parsing logic is broken in @theia/cli. The help doesn't show
the right information.

The issue comes from using yargs at the script level in some places,
leading to corrupt global yargs state.

This commit refactors code around so that --help works as expected.

Fixes #1902

How to test

  • Run yarn
  • Run cd examples\browser
  • yarn theia --help or npx theia --help should display a lot of commands, not just a few parameters.
  • yarn theia <command> --help should display help for that command.
  • yarn theia patate should fail with "unknown command" (code 1).

Review checklist

Reminder for reviewers

@paul-marechal paul-marechal added bug bugs found in the application theia-cli issues related to the theia-cli labels Aug 4, 2021
Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that the help message is fixed by this change:

  • theia --help displays all commands as well as general arguments (--help, --version, --app-target) ✔️
  • theia generate --help shows the command parameters for generate (--mode and --split-frontend) ✔️
  • theia <command> --help shows a general description of every command ✔️
  • The message for running an unknown command was improved from non-existing or no command specified to Unknown command: <command> ✔️
  • Every command still runs as expected (as far as I can tell) ✔️

Code LGTM as well, except for one exception, see below.

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that the cli now displays the proper information:

gitpod /workspace/theia/examples/browser $ yarn theia --help
yarn run v1.22.10
$ /workspace/theia/node_modules/.bin/theia --help
theia <command>

Commands:
  theia start             Start the browser backend
  theia clean             Clean for the browser target
  theia copy              Copy various files from `src-gen` to `lib`
  theia generate          Generate various files for the browser target
  theia build             Generate and bundle the browser frontend using webpack
  theia rebuild           rebuild native node modules for the browser
  theia rebuild:browser   rebuild native node modules for the browser
  theia rebuild:electron  rebuild native node modules for the electron
  theia check:hoisted     Check that all dependencies are hoisted
  theia download:plugins  Download defined external plugins

Options:
  --help        Show help                                              [boolean]
  --version     Show version number                                    [boolean]
  --app-target  The target application type. Overrides `theia.target` in the
                application's package.json      [choices: "browser", "electron"]
Done in 0.54s.
gitpod /workspace/theia/examples/browser $ yarn theia start --help
yarn run v1.22.10
$ /workspace/theia/node_modules/.bin/theia start --help
theia start

Start the browser backend

Options:
  --help        Show help                                              [boolean]
  --version     Show version number                                    [boolean]
  --app-target  The target application type. Overrides `theia.target` in the
                application's package.json      [choices: "browser", "electron"]
Done in 0.88s.

I confirmed it works in electron as well:

gitpod /workspace/theia/examples/electron $ yarn theia --help
yarn run v1.22.10
$ /workspace/theia/node_modules/.bin/theia --help
theia <command>

Commands:
  theia start             Start the electron backend
  theia clean             Clean for the electron target
  theia copy              Copy various files from `src-gen` to `lib`
  theia generate          Generate various files for the electron target
  theia build             Generate and bundle the electron frontend using
                          webpack
  theia rebuild           rebuild native node modules for the electron
  theia rebuild:browser   rebuild native node modules for the browser
  theia rebuild:electron  rebuild native node modules for the electron
  theia check:hoisted     Check that all dependencies are hoisted
  theia download:plugins  Download defined external plugins

Options:
  --help        Show help                                              [boolean]
  --version     Show version number                                    [boolean]
  --app-target  The target application type. Overrides `theia.target` in the
                application's package.json      [choices: "browser", "electron"]
Done in 0.45s.

Did you mean to fail it for an unknown command? (it does fail without the --help flag)

gitpod /workspace/theia/examples/browser $ yarn theia vince --help
yarn run v1.22.10
$ /workspace/theia/node_modules/.bin/theia vince --help
theia <command>

Commands:
  theia start             Start the browser backend
  theia clean             Clean for the browser target
  theia copy              Copy various files from `src-gen` to `lib`
  theia generate          Generate various files for the browser target
  theia build             Generate and bundle the browser frontend using webpack
  theia rebuild           rebuild native node modules for the browser
  theia rebuild:browser   rebuild native node modules for the browser
  theia rebuild:electron  rebuild native node modules for the electron
  theia check:hoisted     Check that all dependencies are hoisted
  theia download:plugins  Download defined external plugins

Options:
  --help        Show help                                              [boolean]
  --version     Show version number                                    [boolean]
  --app-target  The target application type. Overrides `theia.target` in the
                application's package.json      [choices: "browser", "electron"]
Done in 0.63s.

A similar yarn command does:

gitpod /workspace/theia/examples/electron $ yarn vince --help
yarn run v1.22.10
error Command "vince" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@paul-marechal
Copy link
Member Author

@vince-fugnitto I tried addressing your suggestion about invalid commands followed by --help but couldn't figure out something nice, not without fighting yargs itself. Although it allowed me to notice there's a strictCommand API that essentially does the check we were manually doing before for unknown commands, so I used that.

The CLI parsing logic is broken in `@theia/cli`. The help doesn't show
the right information.

The issue comes from using `yargs` at the script level in some places,
leading to corrupt global `yargs` state.

This commit refactors code around so that `--help` works as expected.
@paul-marechal
Copy link
Member Author

I just polished the async queue a bit and fixed CI, turns out the --mode parameter was used both by Theia and Webpack, and I was not passing it to Webpack.

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed under different conditions that the --help displays correctly 👍
I believe it fixes the long standing issue #1902.

@paul-marechal
Copy link
Member Author

#1902 wasn't fixed, but I just pushed a commit that fixes it.

The issue is that doing theia start --help doesn't show Theia's help but theia-cli's help. With this PR it will show Theia's help.

@paul-marechal paul-marechal force-pushed the mp/cli-help-fix branch 2 times, most recently from 50f2101 to 136c414 Compare August 10, 2021 17:56
@paul-marechal paul-marechal merged commit 7d80be9 into master Aug 10, 2021
@paul-marechal paul-marechal deleted the mp/cli-help-fix branch August 10, 2021 19:14
@github-actions github-actions bot added this to the 1.17.0 milestone Aug 10, 2021
dna2github pushed a commit to dna2fork/theia that referenced this pull request Aug 25, 2021
The CLI parsing logic is broken in `@theia/cli`. The help doesn't show
the right information.

The issue comes from using `yargs` at the script level in some places,
leading to corrupt global `yargs` state.

This commit refactors code around so that `--help` works as expected.

`theia start --help` now display's the target application's CLI help
rather than `theia`'s help.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bugs found in the application theia-cli issues related to the theia-cli
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[cli] help seems to not be displayed correctly
3 participants