Skip to content

Commit

Permalink
Merge pull request #2871 from johnjbarton/feat-cli-error-check
Browse files Browse the repository at this point in the history
feat(cli): Warn on commands with underscores.
  • Loading branch information
zzo committed Nov 16, 2017
2 parents d7b725c + 0801a7f commit 35f03b3
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
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
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 35f03b3

Please sign in to comment.