File tree Expand file tree Collapse file tree 3 files changed +5835
-0
lines changed Expand file tree Collapse file tree 3 files changed +5835
-0
lines changed Original file line number Diff line number Diff line change 66const chalk = require ( 'chalk' )
77const semver = require ( 'semver' )
88const 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
913
1014function checkNodeVersion ( wanted , id ) {
1115 if ( ! semver . satisfies ( process . version , wanted ) ) {
@@ -196,6 +200,7 @@ program
196200 program . outputHelp ( )
197201 console . log ( ` ` + chalk . red ( `Unknown command ${ chalk . yellow ( cmd ) } .` ) )
198202 console . log ( )
203+ suggestCommands ( cmd )
199204 } )
200205
201206// add some useful info on help
@@ -230,6 +235,17 @@ if (!process.argv.slice(2).length) {
230235 program . outputHelp ( )
231236}
232237
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+
233249function camelize ( str ) {
234250 return str . replace ( / - ( \w ) / g, ( _ , c ) => c ? c . toUpperCase ( ) : '' )
235251}
You can’t perform that action at this time.
0 commit comments