From 8c90e2f14b1c3de7efc788253f88923468fc111b Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Thu, 21 Nov 2019 09:16:58 +0530 Subject: [PATCH 1/6] feat: suggest matching commands closes #1762 --- src/program.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/program.js b/src/program.js index 865c136ec9..dd99af5fcf 100644 --- a/src/program.js +++ b/src/program.js @@ -323,7 +323,8 @@ Example: $0 --help run. .env(envPrefix) .version(version) .demandCommand(1, 'You must specify a command') - .strict(); + .strict() + .recommendCommands(); program.setGlobalOptions({ 'source-dir': { From af5e8654ae6e104324b18cffe07c4e33113bc9ab Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Thu, 21 Nov 2019 18:33:06 +0530 Subject: [PATCH 2/6] test: add test --- tests/unit/test.program.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/unit/test.program.js b/tests/unit/test.program.js index 4dbe1573a6..6091c4e6e8 100644 --- a/tests/unit/test.program.js +++ b/tests/unit/test.program.js @@ -70,6 +70,15 @@ describe('program.Program', () => { })); }); + it('recommends matching commands', () => { + const program = new Program(['buld']); + return execProgram(program) + .then(makeSureItFails()) + .catch(onlyInstancesOf(UsageError, (error) => { + assert.match(error.message, /Did you mean build/); + })); + }); + it('exits 1 on a thrown error', () => { const fakeProcess = createFakeProcess(); const program = new Program(['cmd']) From 139149f28f282396254a368471345f1693749a22 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Mon, 25 Nov 2019 15:10:19 +0530 Subject: [PATCH 3/6] test: minor fix --- tests/unit/test.program.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test.program.js b/tests/unit/test.program.js index 6091c4e6e8..d22550953a 100644 --- a/tests/unit/test.program.js +++ b/tests/unit/test.program.js @@ -74,9 +74,9 @@ describe('program.Program', () => { const program = new Program(['buld']); return execProgram(program) .then(makeSureItFails()) - .catch(onlyInstancesOf(UsageError, (error) => { + .catch((error) => { assert.match(error.message, /Did you mean build/); - })); + }); }); it('exits 1 on a thrown error', () => { From 57e726adfa1f8d0db5536c79722dea28d570ae76 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 26 Nov 2019 08:51:38 +0530 Subject: [PATCH 4/6] test: new test case --- tests/functional/test.typo.run.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/functional/test.typo.run.js diff --git a/tests/functional/test.typo.run.js b/tests/functional/test.typo.run.js new file mode 100644 index 0000000000..6474c55bd4 --- /dev/null +++ b/tests/functional/test.typo.run.js @@ -0,0 +1,17 @@ +/* @flow */ +import {describe, it} from 'mocha'; + +import { + withTempDir, execWebExt, reportCommandErrors, +} from './common'; + +describe('web-ext', () => { + it('should not accept: --target INVALIDTARGET', async () => { + const argv = ['buld']; + + return execWebExt(argv, {}).waitForExit.then(({exitCode, stderr}) => { + assert.notEqual(exitCode, 0); + assert.match(stderr, /Did you mean build/); + }); + }); +}); \ No newline at end of file From b946be634def8556b3cdeab33f2f12a5fa5e6ca1 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 26 Nov 2019 08:54:06 +0530 Subject: [PATCH 5/6] test: revert --- tests/functional/test.typo.run.js | 2 +- tests/unit/test.program.js | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/tests/functional/test.typo.run.js b/tests/functional/test.typo.run.js index 6474c55bd4..52f025b596 100644 --- a/tests/functional/test.typo.run.js +++ b/tests/functional/test.typo.run.js @@ -6,7 +6,7 @@ import { } from './common'; describe('web-ext', () => { - it('should not accept: --target INVALIDTARGET', async () => { + it('recommends matching command', async () => { const argv = ['buld']; return execWebExt(argv, {}).waitForExit.then(({exitCode, stderr}) => { diff --git a/tests/unit/test.program.js b/tests/unit/test.program.js index d22550953a..4dbe1573a6 100644 --- a/tests/unit/test.program.js +++ b/tests/unit/test.program.js @@ -70,15 +70,6 @@ describe('program.Program', () => { })); }); - it('recommends matching commands', () => { - const program = new Program(['buld']); - return execProgram(program) - .then(makeSureItFails()) - .catch((error) => { - assert.match(error.message, /Did you mean build/); - }); - }); - it('exits 1 on a thrown error', () => { const fakeProcess = createFakeProcess(); const program = new Program(['cmd']) From 9d1b2216ba49e7a415f2dac2e7ec16c4b9e05d98 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 26 Nov 2019 15:46:04 +0530 Subject: [PATCH 6/6] test: fixup --- tests/functional/test.typo.run.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/functional/test.typo.run.js b/tests/functional/test.typo.run.js index 52f025b596..9a6132f95c 100644 --- a/tests/functional/test.typo.run.js +++ b/tests/functional/test.typo.run.js @@ -1,9 +1,8 @@ /* @flow */ import {describe, it} from 'mocha'; +import {assert} from 'chai'; -import { - withTempDir, execWebExt, reportCommandErrors, -} from './common'; +import {execWebExt} from './common'; describe('web-ext', () => { it('recommends matching command', async () => {