From 0801a7f1e6b4b214d7268cb44b1dbc7138e46964 Mon Sep 17 00:00:00 2001 From: johnjbarton Date: Thu, 9 Nov 2017 09:34:21 -0800 Subject: [PATCH] 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. --- lib/cli.js | 3 +++ test/unit/cli.spec.js | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/cli.js b/lib/cli.js index a86f837b9..4bd4aad83 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -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() diff --git a/test/unit/cli.spec.js b/test/unit/cli.spec.js index 7696cb823..a48707776 100644 --- a/test/unit/cli.spec.js +++ b/test/unit/cli.spec.js @@ -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', () => {