Skip to content

Commit 0801a7f

Browse files
committed
feat(cli): Warn on commands with underscores.
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.
1 parent 5a6725a commit 0801a7f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/cli.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ var processArgs = function (argv, options, fs, path) {
2121
Object.getOwnPropertyNames(argv).forEach(function (name) {
2222
var argumentValue = argv[name]
2323
if (name !== '_' && name !== '$0') {
24+
if (name.indexOf('_') !== -1) {
25+
throw new Error('Bad argument: ' + name + ' did you mean ' + name.replace('_', '-'))
26+
}
2427
if (Array.isArray(argumentValue)) {
2528
// If the same argument is defined multiple times, override.
2629
argumentValue = argumentValue.pop()

test/unit/cli.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,18 @@ describe('cli', () => {
183183
expect(options.addedFiles).to.deep.equal(['a1.js', 'a2.js'])
184184
expect(options.changedFiles).to.deep.equal(['ch1.js', 'ch2.js'])
185185
})
186+
187+
it('should error on args with underscores', () => {
188+
var expectedException
189+
try {
190+
var options = processArgs(['--no_browsers'])
191+
expectedException = 'Should have thrown but got ' + options
192+
} catch (e) {
193+
expectedException = e
194+
} finally {
195+
expect(expectedException + '').to.equal('Error: Bad argument: no_browsers did you mean no-browsers')
196+
}
197+
})
186198
})
187199

188200
describe('parseClientArgs', () => {

0 commit comments

Comments
 (0)