File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import program from 'commander';
2
2
import pjson from '../../package.json' ;
3
3
import chalk from 'chalk' ;
4
4
5
+ const availableCommands = [ 'init' , 'list' , 'search' , 'info' ] ;
6
+
5
7
program
6
8
. version ( pjson . version )
7
9
. option ( '-v, --version' , 'check version' )
@@ -11,13 +13,16 @@ program
11
13
. command ( 'search [term]' , 'Search for MERN variant' )
12
14
. command ( 'info [term]' , 'View details of a MERN variant' )
13
15
. arguments ( '<command>' )
14
- . action ( ( cmd ) => {
15
- program . outputHelp ( )
16
- console . log ( ` ` + chalk . yellow ( `\n Unknown command ${ chalk . green ( cmd ) } ` ) )
17
- console . log ( )
18
- } )
19
16
. parse ( process . argv ) ;
20
17
18
+ if ( program . args . length >= 1 ) {
19
+ if ( ! availableCommands . includes ( program . args [ 0 ] ) ) {
20
+ program . outputHelp ( )
21
+ console . log ( ` ` + chalk . red ( `\n Unknown command ${ chalk . yellow ( program . args [ 0 ] ) } .` ) )
22
+ console . log ( )
23
+ }
24
+ }
25
+
21
26
if ( ! program . args . length ) {
22
27
program . help ( ) ;
23
28
}
You can’t perform that action at this time.
0 commit comments