Skip to content

Commit

Permalink
feat(cli): Warn on commands with underscores.
Browse files Browse the repository at this point in the history
The cli silently ignores unknown options. Until we can fix this, a simple
improvement is to warn on options with underscores. In our experience, --no_browsers
is common user error that gives confusion because browsers are used.
  • Loading branch information
johnjbarton committed Nov 16, 2017
1 parent 5a6725a commit 0801a7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var processArgs = function (argv, options, fs, path) {
Object.getOwnPropertyNames(argv).forEach(function (name) {
var argumentValue = argv[name]
if (name !== '_' && name !== '$0') {
if (name.indexOf('_') !== -1) {
throw new Error('Bad argument: ' + name + ' did you mean ' + name.replace('_', '-'))
}
if (Array.isArray(argumentValue)) {
// If the same argument is defined multiple times, override.
argumentValue = argumentValue.pop()
Expand Down
12 changes: 12 additions & 0 deletions test/unit/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ describe('cli', () => {
expect(options.addedFiles).to.deep.equal(['a1.js', 'a2.js'])
expect(options.changedFiles).to.deep.equal(['ch1.js', 'ch2.js'])
})

it('should error on args with underscores', () => {
var expectedException
try {
var options = processArgs(['--no_browsers'])
expectedException = 'Should have thrown but got ' + options
} catch (e) {
expectedException = e
} finally {
expect(expectedException + '').to.equal('Error: Bad argument: no_browsers did you mean no-browsers')
}
})
})

describe('parseClientArgs', () => {
Expand Down

0 comments on commit 0801a7f

Please sign in to comment.