@@ -7,7 +7,7 @@ const pkg = require('../package');
77const args = process . argv . slice ( 2 ) ;
88const arg_0 = args [ 0 ] ;
99
10- if ( ! ! ~ [ '-v' , '--version' ] . indexOf ( arg_0 ) ) {
10+ if ( arg_0 && ! ! ~ [ '-v' , '--version' ] . indexOf ( arg_0 . toLowerCase ( ) ) ) {
1111 console . log ( pkg . version ) ;
1212 process . exit ( 0 ) ;
1313}
@@ -35,22 +35,30 @@ if (!arg_0) {
3535 console . log ( ) ;
3636 console . log ( ' Options:' ) ;
3737 console . log ( ) ;
38- console . log ( ' -v, --version show version and exit' ) ;
38+ console . log ( ' -v, --version output version and exit' ) ;
39+ console . log ( ' -s, --silent output port without verbose log' ) ;
3940 console . log ( ' -h, --help output usage information' ) ;
4041 console . log ( ) ;
4142 console . log ( ' Further help:' ) ;
4243 console . log ( ) ;
4344 console . log ( ` ${ pkg . homepage } ` ) ;
4445 console . log ( ) ;
4546} else {
47+ const isSilent = ! ! ~ process . argv . indexOf ( '-s' ) || ! ! ~ process . argv . indexOf ( '--silent' ) ;
48+
4649 main ( port , ( err , _port ) => {
47- if ( err ) {
48- console . log ( `get available port failed with ${ err } ` ) ;
49- }
50+ if ( isSilent ) {
51+ console . log ( _port || port ) ;
52+ } else {
53+ if ( err ) {
54+ console . log ( `get available port failed with ${ err } ` ) ;
55+ }
56+
57+ if ( port !== _port ) {
58+ console . log ( `port ${ port } was occupied` ) ;
59+ }
5060
51- if ( port !== _port ) {
52- console . log ( `port ${ port } was occupied` ) ;
61+ console . log ( `get available port ${ _port } ` ) ;
5362 }
54- console . log ( `get available port ${ _port } ` ) ;
5563 } ) ;
5664}
0 commit comments