-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
allowUnknownFlags
options (#169)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
- Loading branch information
1 parent
a0ce744
commit a27ff12
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import path from 'path'; | ||
import test from 'ava'; | ||
import execa from 'execa'; | ||
|
||
const fixtureAllowUnknownFlags = path.join(__dirname, 'fixtures', 'fixture-allow-unknown-flags.js'); | ||
|
||
test('spawn CLI and test specifying unknown flags', async t => { | ||
const error = await t.throwsAsync( | ||
execa(fixtureAllowUnknownFlags, ['--foo', 'bar', '--unspecified-a', '--unspecified-b', 'input-is-allowed']), | ||
{ | ||
message: /^Command failed with exit code 2/ | ||
} | ||
); | ||
const {stderr} = error; | ||
t.regex(stderr, /Unknown flags/); | ||
t.regex(stderr, /--unspecified-a/); | ||
t.regex(stderr, /--unspecified-b/); | ||
t.notRegex(stderr, /input-is-allowed/); | ||
}); | ||
|
||
test('spawn CLI and test specifying known flags', async t => { | ||
const {stdout} = await execa(fixtureAllowUnknownFlags, ['--foo', 'bar']); | ||
t.is(stdout, 'bar'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
const meow = require('../..'); | ||
|
||
const cli = meow({ | ||
description: 'Custom description', | ||
help: ` | ||
Usage | ||
foo <input> | ||
`, | ||
allowUnknownFlags: false, | ||
flags: { | ||
foo: { | ||
type: 'string' | ||
} | ||
} | ||
}); | ||
|
||
console.log(cli.flags.foo); |