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

gatsby-cli error semantics Did you mean <command>? doesn't correctly convey command options given #12078

Closed
anthonytranDev opened this issue Feb 25, 2019 · 5 comments
Labels
good first issue Issue that doesn't require previous experience with Gatsby help wanted Issue with a clear description that the community can help with. type: documentation An issue or pull request for improving or updating Gatsby's documentation

Comments

@anthonytranDev
Copy link
Contributor

anthonytranDev commented Feb 25, 2019

Description

When gatsby y develop has been typed. The resulting stdout suggests Did you mean new ?, more precisely new being very different from develop. Doesn't accurately depict the command typed in

Steps to reproduce

Demo Project - not required
Start up a new project gatsby and type in gatsby y develop

Expected result

Did you mean develop?

Actual result

Did you mean new?

Solution Suggestions

Include the following criteria

  1. Increase the accuracy of string search with a list of suggestions
// Example based on npm
$ npm istall

// Result
Did you mean one of these?
    install
    uninstall
    star
  1. Notify developer that the command is wrong and throw error
// Example of incorrect yarn command entered
$ yarn a upgrade

// result
yarn run v1.13.0
error Command "a" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentat
ion about this command.

Environment

  System:
    OS: macOS Mojave 10.14.3
    CPU: x64 Intel(R) Core(TM) i5-7567U CPU @ 3.50GHz
    Shell: 3.2.57(1)-release - /bin/bash
  Binaries:
    Node: v10.14.2 - /Users/anthonytran/.nvm/versions/node/v10.14.2/bin/node
    npx: v6.5.0 - /Users/anthonytran/.nvm/versions/node/v10.14.2/bin/npx
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 6.5.0 - /Users/anthonytran/.nvm/node_modules/.bin
    gatsby: 2.4.8 - /Users/anthonytran/.config/yarn/global/node_modules/gatsby-cli
  Browsers:
    Chrome: 72.0.3626.109
  npmPackages:
     dependencies
      gatsby: ^2.1.16,
      gatsby-image: ^2.0.29,
      gatsby-plugin-manifest: ^2.0.18,
      gatsby-plugin-offline: ^2.0.24,
      gatsby-plugin-react-helmet: ^3.0.6,
      gatsby-plugin-sharp: ^2.0.21,
      gatsby-source-filesystem: ^2.0.22,
      gatsby-transformer-sharp: ^2.1.14,
      prop-types: ^15.7.2,
      react: ^16.8.3,
      react-dom: ^16.8.3,
      react-helmet: ^5.2.0

File contents (if changed)

gatsby-config.js: N/A
package.json: N/A
gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A

@anthonytranDev anthonytranDev changed the title Semantic CLI Did you mean <command>? doesn't correctly convey command options given gatsby-cli error semantics Did you mean <command>? doesn't correctly convey command options given Feb 25, 2019
@freiksenet freiksenet added help wanted Issue with a clear description that the community can help with. type: documentation An issue or pull request for improving or updating Gatsby's documentation good first issue Issue that doesn't require previous experience with Gatsby type: feature or enhancement labels Feb 26, 2019
@freiksenet
Copy link
Contributor

I think that's a good idea (pinging @gatsbyjs/docs just to make sure). Do you want to make a PR to add this feature? Thanks a lot!

@wardpeet
Copy link
Contributor

some extra info: we use yargs as a cli parser. Code can be found https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-cli/src/create-cli.js. Yargs as an option to add completion text to the cli. Currently I don't think we use it.

reference: http://yargs.js.org/docs/#api-completioncmd-description-fn

@anthonytranDev
Copy link
Contributor Author

anthonytranDev commented Feb 26, 2019

@freiksenet @wardpeet Just made a PR to the gatsby-cli codebase. My aim here to improve the DX for y'all.

Questions

Do I need to submit a feature request first?
Is @wardpeet the person responsible for the gatsby-cli package?

@freiksenet
Copy link
Contributor

freiksenet commented Feb 26, 2019

Awesome 👍 You can just create a PR. We don't really have separate responsible people per packages, everyone in Gatsby team is responsible :)

This was referenced Mar 7, 2019
sidharthachatterjee pushed a commit that referenced this issue Mar 8, 2019
* chore(gatsby-cli): Add meant dependency (#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

* feat: implemention of did you mean suggestion (#12078)

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

* Modify gatsby-cli include command suggestion (#12078)

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

* fix(gatsby-cli): demandCommand was changed back to original (#12078)
@anthonytranDev
Copy link
Contributor Author

This issue has now been resolved. It is now part of gatsby-cli@2.4.14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issue that doesn't require previous experience with Gatsby help wanted Issue with a clear description that the community can help with. type: documentation An issue or pull request for improving or updating Gatsby's documentation
Projects
None yet
Development

No branches or pull requests

3 participants