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(gatsby-cli): Better suggestions #12392

Conversation

anthonytranDev
Copy link
Contributor

Description

Gatsby-cli will give more accurate suggestion(s) upon fail.

Related Issues

This is #12078

Who uses `meant`: This package is used by NPM.

Implementation: Used to mimic the  same UX of giving command suggestions, upon failure to provide correct command

Additional Reasons to use package:
- Zero Dependencies attached
- Only 30 lines of POJO - very lightweight
- Very few issues with current versions

Please checkout: https://www.npmjs.com/package/meant
This code has been duplicated from NPM 6.8.0 with minor tweaks.

Tweaks:
- Style changes of using string template literals over single quotes
- newlines - \n added to the end to line 10 and line 13, to make the code more developer friendly
Line 328 - alter demandCommand - message string `Pass --help ...` will not show, because cli.fail method (330 line) is utilise. Thus message string has been moved to function 285.
Another reason it has been moved there is organise al suggestions into one place

Line 318 - showHelpOnFail could not get access to `yargs` thus cli.fail function was used instead

Line 319 - `recommendCommands`, did not recommend commands were not very accurate, thus cli.fail was used configured more specific commands and show multiple command suggestions
@anthonytranDev anthonytranDev marked this pull request as ready for review March 8, 2019 00:01
@anthonytranDev anthonytranDev requested a review from a team as a code owner March 8, 2019 00:01
Copy link
Contributor

@sidharthachatterjee sidharthachatterjee left a comment

Choose a reason for hiding this comment

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

This is great, @anthonytranDev 👍

Left a small comment!


cli.showHelp()
report.log(suggestion)
report.log(msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be log the msg as well?

~/Code/gatsby/www feat/gatsby-cli-suggestions*
❯ ./node_modules/gatsby-cli/lib/index.js ne .
Usage: node_modules/gatsby-cli/lib/index.js <command> [options]

Commands:
  develop                   Start development server. Watches files, rebuilds, and hot reloads if something changes
  build                     Build a Gatsby project.
  serve                     Serve previously built Gatsby site.
  info                      Get environment information for debugging and issue reporting
  clean                     Wipe the local gatsby environment including built assets and cache
  repl                      Get a node repl with context of Gatsby environment, see (add docs link here)
  new [rootPath] [starter]  Create new Gatsby project.

Options:
  --verbose      Turn on verbose output                                                                                                                                       [boolean] [default: false]
  --no-color     Turn off the color in output                                                                                                                                 [boolean] [default: false]
  -h, --help     Show help                                                                                                                                                                     [boolean]
  -v, --version  Show version number                                                                                                                                                           [boolean]


Did you mean this?
     new

Unknown arguments: ne, .

In this case, maybe we can do without the Unknown arguments bit. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this is good to have for future proofing as correctly pointed out by @pieh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to let you know, I decided to log the msg as Unknown arguments: <args> as it clearly states the mistakes the user has made.

This will help Newcomers and Junior Developers like myself take up Gatsby faster.

The ethos here is copy a Rust Lang level of stderr, as to makes it so obvious, that it makes Gatsby easier to adopt

Nonetheless I've been thinking of some improvements, that can be made to make the Unknown arguments: <args> part more readable and aesthically pleasing to Gatsby Community

I've already got some ideas, plus it would be nice to hear back on what you guys think 😄

@sidharthachatterjee sidharthachatterjee changed the title Feat/gatsby cli suggestions feat(gatsby-cli) better suggestions Mar 8, 2019
@sidharthachatterjee sidharthachatterjee merged commit 2e96660 into gatsbyjs:master Mar 8, 2019
@gatsbot
Copy link

gatsbot bot commented Mar 8, 2019

Holy buckets, @anthonytranDev — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (Currently we’ve got a couple t-shirts available, plus some socks that are really razzing our berries right now.)
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again!

@sidharthachatterjee
Copy link
Contributor

Published in gatsby-cli@2.4.14

@anthonytranDev anthonytranDev changed the title feat(gatsby-cli) better suggestions feat(gatsby-cli): Better suggestions Mar 8, 2019
@anthonytranDev anthonytranDev deleted the feat/gatsby-cli-suggestions branch March 8, 2019 16:01
@anthonytranDev anthonytranDev restored the feat/gatsby-cli-suggestions branch March 8, 2019 16:01
@anthonytranDev anthonytranDev deleted the feat/gatsby-cli-suggestions branch March 8, 2019 16:01
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.

None yet

2 participants