Skip to content

Commit

Permalink
fix: Report error if unwanted positional arguments are received
Browse files Browse the repository at this point in the history
This applies to check-coverage, instrument, merge and report.  Passing
additional arguments will now cause the help script to be displayed and
an error exit code.

Unknown flags `nyc report --unknown=1` are still not reported.
Reporting unknown flags would require additional work as
`yargs.strict()` causes unknown items from configuration to be reported,
including flags that are defined for the global command but not a
sub-command.

Fixes #401
  • Loading branch information
coreyfarrell committed May 6, 2019
1 parent 21fe1e7 commit fc2a5b5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/commands/check-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exports.describe = 'check whether coverage is within thresholds provided'

exports.builder = function (yargs) {
yargs
.demandCommand(0, 0)
.option('exclude', {
alias: 'x',
default: testExclude.defaultExclude,
Expand Down
9 changes: 9 additions & 0 deletions lib/commands/instrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ exports.describe = 'instruments a file or a directory tree and writes the instru

exports.builder = function (yargs) {
return yargs
.demandCommand(0, 0)
.positional('input', {
describe: 'file or directory to instrument',
type: 'text'
})
.positional('output', {
describe: 'directory to output instrumented files',
type: 'text'
})
.option('require', {
alias: 'i',
default: [],
Expand Down
1 change: 1 addition & 0 deletions lib/commands/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exports.describe = 'merge istanbul format coverage output in a given folder'

exports.builder = function (yargs) {
return yargs
.demandCommand(0, 0)
.positional('input-directory', {
describe: 'directory containing multiple istanbul coverage files',
type: 'text',
Expand Down
1 change: 1 addition & 0 deletions lib/commands/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exports.describe = 'run coverage report for .nyc_output'

exports.builder = function (yargs) {
return yargs
.demandCommand(0, 0)
.option('reporter', {
alias: 'r',
describe: 'coverage reporter(s) to use',
Expand Down
2 changes: 1 addition & 1 deletion test/nyc-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ t.test('--check-coverage fails when check-coverage command is used rather than f
return testSuccess(t, {
args: [process.execPath, './half-covered.js']
}).then(() => testFailure(t, {
args: ['check-coverage', '--lines', '51', process.execPath, './half-covered.js']
args: ['check-coverage', '--lines', '51']
}))
})

Expand Down

0 comments on commit fc2a5b5

Please sign in to comment.