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

Show CLI help when user passed unknown option #837

Closed
bahmutov opened this issue Oct 27, 2017 · 4 comments · Fixed by #1615
Closed

Show CLI help when user passed unknown option #837

bahmutov opened this issue Oct 27, 2017 · 4 comments · Fixed by #1615
Assignees
Labels
cli type: enhancement Requested enhancement of existing feature type: user experience Improvements needed for UX
Milestone

Comments

@bahmutov
Copy link
Contributor

Feature

All versions of Cypress

When a user passes unknown CLI option we just die.

$(npm bin)/cypress open --foo

  error: unknown option `--foo'

First, the quotes are wrong around --foo, second we should display help message right away to show the right options for that command. Simple to do by replacing commander method

commander.Command.prototype.unknownOption = function(flag) {
  if (this._allowUnknownOption) return;
  console.error();
  console.error("  error: unknown option '%s'", flag);
  console.error();
  this.outputHelp()
  process.exit(1);
};
@bahmutov bahmutov self-assigned this Oct 27, 2017
@bahmutov bahmutov added cli type: enhancement Requested enhancement of existing feature type: user experience Improvements needed for UX labels Oct 27, 2017
@slawiko
Copy link

slawiko commented Apr 19, 2018

Is this issue about DO NOT FAIL IF PASSED UNKNOWN OPTION? I think CLI shouldn't fail in such cases. What about you?

@bahmutov
Copy link
Contributor Author

No, this issue is just that it is not enough to say "wrong option" and exit with error code 1, but the app needs to show valid options and then exit with error code 1. Exiting with error is good - otherwise the user will never know they are doing something wrong.

@bahmutov
Copy link
Contributor Author

Here is the fixed output

$ npm run cypress:open -- --foo

> cypress@2.1.0 cypress:open /Users/gleb/git/cypress
> node ./cli/bin/cypress open --dev --global "--foo"


  error: unknown option '--foo'


  Usage: open [options]

  Opens Cypress in the interactive GUI.


  Options:

    -p, --port <port>             runs Cypress on a specific port. overrides any value in cypress.json.
    -e, --env <env>               sets environment variables. separate multiple values with a comma. overrides any value in cypress.json or cypress.env.json
    -c, --config <config>         sets configuration values. separate multiple values with a comma. overrides any value in cypress.json.
    -d, --detached [bool]         runs Cypress application in detached mode
    -P, --project <project path>  path to the project
    --global                      force Cypress into global mode as if its globally installed
    --dev                         runs cypress in development and bypasses binary check
    -h, --help                    output usage information
npm ERR! code ELIFECYCLE
npm ERR! errno 1

@jennifer-shehane jennifer-shehane added this to the 3.0.0 milestone May 15, 2018
jennifer-shehane pushed a commit that referenced this issue May 15, 2018
* cli: if user passed unknown option, show help and exit, close #837

* cli: test unknown option output

* linting
@jennifer-shehane jennifer-shehane added stage: pending release and removed stage: pending release stage: investigating Someone from Cypress is looking into this stage: needs investigating Someone from Cypress needs to look at this stage: ready for work The issue is reproducible and in scope labels May 24, 2018
@brian-mann
Copy link
Member

Released in 3.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli type: enhancement Requested enhancement of existing feature type: user experience Improvements needed for UX
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants