File tree 3 files changed +5835
-0
lines changed
3 files changed +5835
-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 ) ) {
@@ -196,6 +200,7 @@ program
196
200
program . outputHelp ( )
197
201
console . log ( ` ` + chalk . red ( `Unknown command ${ chalk . yellow ( cmd ) } .` ) )
198
202
console . log ( )
203
+ suggestCommands ( cmd )
199
204
} )
200
205
201
206
// add some useful info on help
@@ -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 . red ( `Did you mean ${ chalk . yellow ( suggestion ) } ?` ) )
246
+ }
247
+ }
248
+
233
249
function camelize ( str ) {
234
250
return str . replace ( / - ( \w ) / g, ( _ , c ) => c ? c . toUpperCase ( ) : '' )
235
251
}
You can’t perform that action at this time.
0 commit comments