File tree 2 files changed +17
-0
lines changed 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 6
6
const chalk = require ( 'chalk' )
7
7
const semver = require ( 'semver' )
8
8
const requiredVersion = require ( '../package.json' ) . engines . node
9
+ const didYouMean = require ( 'didyoumean' )
10
+
11
+ // Setting edit distance to 60% of the input string's length
12
+ didYouMean . threshold = 0.6
9
13
10
14
function checkNodeVersion ( wanted , id ) {
11
15
if ( ! semver . satisfies ( process . version , wanted ) ) {
@@ -193,6 +197,7 @@ program
193
197
program
194
198
. arguments ( '<command>' )
195
199
. action ( ( cmd ) => {
200
+ suggestCommands ( cmd )
196
201
program . outputHelp ( )
197
202
console . log ( ` ` + chalk . red ( `Unknown command ${ chalk . yellow ( cmd ) } .` ) )
198
203
console . log ( )
@@ -230,6 +235,17 @@ if (!process.argv.slice(2).length) {
230
235
program . outputHelp ( )
231
236
}
232
237
238
+ function suggestCommands ( cmd ) {
239
+ const availableCommands = program . commands . map ( cmd => {
240
+ return cmd . _name
241
+ } )
242
+
243
+ const suggestion = didYouMean ( cmd , availableCommands )
244
+ if ( suggestion ) {
245
+ console . log ( chalk . cyan ( `Warning: ${ chalk . yellow ( `Did you mean ${ suggestion } ?` ) } ` ) )
246
+ }
247
+ }
248
+
233
249
function camelize ( str ) {
234
250
return str . replace ( / - ( \w ) / g, ( _ , c ) => c ? c . toUpperCase ( ) : '' )
235
251
}
Original file line number Diff line number Diff line change 33
33
"commander" : " ^2.20.0" ,
34
34
"debug" : " ^4.1.0" ,
35
35
"deepmerge" : " ^3.2.0" ,
36
+ "didyoumean" : " ^1.2.1" ,
36
37
"download-git-repo" : " ^1.0.2" ,
37
38
"ejs" : " ^2.6.1" ,
38
39
"envinfo" : " ^7.1.0" ,
You can’t perform that action at this time.
0 commit comments