From 845275a20a7a2e5b30d94eba2a6d6d56f4682bae Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Thu, 1 Aug 2019 21:51:21 +0530 Subject: [PATCH 1/3] Suggest matching commands if the user mistypes --- lib/cli/bin/generate.js | 7 ++++++- lib/cli/package.json | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/cli/bin/generate.js b/lib/cli/bin/generate.js index 1fb6b6c8720..bbcc5bc047a 100644 --- a/lib/cli/bin/generate.js +++ b/lib/cli/bin/generate.js @@ -1,6 +1,7 @@ import program from 'commander'; import chalk from 'chalk'; import envinfo from 'envinfo'; +import didYouMean from 'didyoumean'; import pkg from '../package.json'; import initiate from '../lib/initiate'; import { codeLog } from '../lib/helpers'; @@ -70,7 +71,11 @@ if (process.argv[1].includes('getstorybook')) { }); program.command('*', { noHelp: true }).action(cmd => { - logger.error('Invalid command: %s.\nSee --help for a list of available commands.', cmd); + logger.error(' Invalid command: %s.\n See --help for a list of available commands.', cmd); + const suggestion = didYouMean(cmd, program.commands.map(cmd => cmd._name)); + if (suggestion) { + logger.log(`\n Did you mean ${suggestion}?`); + } process.exit(1); }); diff --git a/lib/cli/package.json b/lib/cli/package.json index 87c804cf4e2..2dccbfe73fe 100644 --- a/lib/cli/package.json +++ b/lib/cli/package.json @@ -35,6 +35,7 @@ "commander": "^2.19.0", "core-js": "^3.0.1", "cross-spawn": "^6.0.5", + "didyoumean": "^1.2.1", "envinfo": "^7.3.1", "fs-extra": "^8.0.1", "inquirer": "^6.2.0", From 8783c4a3d4ecd42eaff7b36ef41a53215403b65b Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Sat, 3 Aug 2019 07:11:13 +0530 Subject: [PATCH 2/3] Update yarn.lock --- yarn.lock | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/yarn.lock b/yarn.lock index 11d4e2d7976..cbd5d037b76 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10345,6 +10345,11 @@ dezalgo@^1.0.0: asap "^2.0.0" wrappy "1" +didyoumean@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/didyoumean/-/didyoumean-1.2.1.tgz#e92edfdada6537d484d73c0172fd1eba0c4976ff" + integrity sha1-6S7f2tplN9SE1zwBcv0eugxJdv8= + diff-sequences@^24.3.0: version "24.3.0" resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-24.3.0.tgz#0f20e8a1df1abddaf4d9c226680952e64118b975" From f7f9a15f13506e810c7a78f267f6ae1e07dc2163 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Mon, 5 Aug 2019 18:12:43 +0530 Subject: [PATCH 3/3] fix: lint --- lib/cli/bin/generate.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/cli/bin/generate.js b/lib/cli/bin/generate.js index bbcc5bc047a..8b567ea54b2 100644 --- a/lib/cli/bin/generate.js +++ b/lib/cli/bin/generate.js @@ -70,11 +70,15 @@ if (process.argv[1].includes('getstorybook')) { }); }); - program.command('*', { noHelp: true }).action(cmd => { - logger.error(' Invalid command: %s.\n See --help for a list of available commands.', cmd); - const suggestion = didYouMean(cmd, program.commands.map(cmd => cmd._name)); + program.command('*', { noHelp: true }).action(invalidCmd => { + logger.error( + ' Invalid command: %s.\n See --help for a list of available commands.', + invalidCmd + ); + // eslint-disable-next-line + const suggestion = didYouMean(invalidCmd, program.commands.map(cmd => cmd._name)); if (suggestion) { - logger.log(`\n Did you mean ${suggestion}?`); + logger.log(`\n Did you mean ${suggestion}?`); } process.exit(1); });