cli: handle help, -h and --help, close #463 (#464)

This commit is contained in:
Gleb Bahmutov
2017-09-13 14:11:36 -04:00
committed by GitHub
parent 70a7fa0572
commit 901d62b887
3 changed files with 128 additions and 1 deletions
+106
View File
@@ -1,3 +1,108 @@
exports['cli help command shows help 1'] = `
command: bin/cypress help
code: 0
failed: false
killed: false
signal: null
timedOut: false
stdout:
-------
Usage: cypress [options] [command]
Commands:
help Shows CLI help and exits
version Prints Cypress version
run [options] Runs Cypress tests from the CLI without the GUI
open [options] Opens Cypress in the interactive GUI.
install Installs the Cypress executable matching this package's version
verify Verifies that Cypress is installed correctly and executable
Options:
-h, --help output usage information
-v, --version Prints Cypress version
-------
stderr:
-------
-------
`
exports['cli help command shows help for -h 1'] = `
command: bin/cypress -h
code: 0
failed: false
killed: false
signal: null
timedOut: false
stdout:
-------
Usage: cypress [options] [command]
Commands:
help Shows CLI help and exits
version Prints Cypress version
run [options] Runs Cypress tests from the CLI without the GUI
open [options] Opens Cypress in the interactive GUI.
install Installs the Cypress executable matching this package's version
verify Verifies that Cypress is installed correctly and executable
Options:
-h, --help output usage information
-v, --version Prints Cypress version
-------
stderr:
-------
-------
`
exports['cli help command shows help for --help 1'] = `
command: bin/cypress --help
code: 0
failed: false
killed: false
signal: null
timedOut: false
stdout:
-------
Usage: cypress [options] [command]
Commands:
help Shows CLI help and exits
version Prints Cypress version
run [options] Runs Cypress tests from the CLI without the GUI
open [options] Opens Cypress in the interactive GUI.
install Installs the Cypress executable matching this package's version
verify Verifies that Cypress is installed correctly and executable
Options:
-h, --help output usage information
-v, --version Prints Cypress version
-------
stderr:
-------
-------
`
exports['cli unknown command shows usage and exits 1'] = `
command: bin/cypress foo
@@ -16,6 +121,7 @@ exports['cli unknown command shows usage and exits 1'] = `
Commands:
help Shows CLI help and exits
version Prints Cypress version
run [options] Runs Cypress tests from the CLI without the GUI
open [options] Opens Cypress in the interactive GUI.
+8 -1
View File
@@ -29,7 +29,7 @@ const descriptions = {
version: 'Prints Cypress version',
}
const knownCommands = ['version', 'run', 'open', 'install', 'verify', '-v', '--version']
const knownCommands = ['version', 'run', 'open', 'install', 'verify', '-v', '--version', 'help', '-h', '--help']
const text = (description) => {
if (!descriptions[description]) {
@@ -51,6 +51,13 @@ module.exports = {
// in usage help docs
program._name = 'cypress'
program
.command('help')
.description('Shows CLI help and exits')
.action(() => {
program.help()
})
program
.option('-v, --version', text('version'))
.command('version')
+14
View File
@@ -20,6 +20,20 @@ describe('cli', function () {
this.exec = (args) => cli.init(`node test ${args}`.split(' '))
})
context('help command', () => {
it('shows help', () =>
execa('bin/cypress', ['help']).then(snapshot)
)
it('shows help for -h', () =>
execa('bin/cypress', ['-h']).then(snapshot)
)
it('shows help for --help', () =>
execa('bin/cypress', ['--help']).then(snapshot)
)
})
context('unknown command', () => {
it('shows usage and exits', () =>
execa('bin/cypress', ['foo']).then(snapshot)