nuxt / create-nuxt-app

Create Nuxt.js App in seconds.
MIT License
3.48k stars 429 forks source link

feat(cli): add user-friendly exit for unknown options #854

Closed NozomuIkuta closed 2 years ago

NozomuIkuta commented 3 years ago

This PR has no related issues.

I added a logic for CNA to show help message instead of raw error stack in case a user (like me 1 hour ago) passes unknown options. By doing so, the user can find what he/she really wanted and copy it quickly, without running help command or seeing documentation.


Explanation of work

I felt the try-catch block long so I extracted the main part in run function. If you prefer inlined version as before, let me know.

How I tested

  1. Ran node lib/cli.js test --unknown-options, and checked the output (for what I added)
  2. Ran node lib/cli.js test with throw new Error('Custom Message') added before run function call, and checked the output (for backward compatibility)
  3. Ran node lib/cli.js test, and checked the output (for backward compatibility, it shows "not empty" error with exit code 0)