Skip to content

Commit

Permalink
fix: show help when unknown command is given (#52)
Browse files Browse the repository at this point in the history
Related to <yargs/yargs#287>.
  • Loading branch information
ybiquitous committed Nov 15, 2017
1 parent 321903f commit 5881bbd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = function cli() {
.usage('$0 <command>')
.command('init', init.desc, {}, init)
.demandCommand(1)
.strict()
.alias('help', 'h')
.alias('version', 'v')
.argv
Expand Down
20 changes: 13 additions & 7 deletions test/help.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ Options:
`.trim()

suite('help', () => {
test('without any arguments', async () => {
const error = await assertThrows(() => exec())
const { code, stdout, stderr } = error
assert(error instanceof Error)
assert(code === 1)
assert(stdout === '')
assert(stderr.includes(HELP), stderr)
[
[],
['unknown'],
['unknown', 'xyz'],
].forEach((args) => {
test(`with arguments [${args.join(', ')}]`, async () => {
const error = await assertThrows(() => exec(...args))
const { code, stdout, stderr } = error
assert(error instanceof Error)
assert(code === 1)
assert(stdout === '')
assert(stderr.includes(HELP), stderr)
})
});

['--help', '-h'].forEach((option) => {
Expand Down

0 comments on commit 5881bbd

Please sign in to comment.