@@ -24,14 +24,14 @@ module.exports = (() => {
2424
2525 load ( ) {
2626 const frameworkCmdsPaths = walkSync ( `${ appRoot } ` , { globs : [ 'lib/plugins/*/index.js' ] } )
27- . map ( ( val ) => ( `${ appRoot } /${ val } ` ) ) ;
27+ . map ( val => ( `${ appRoot } /${ val } ` ) ) ;
2828
2929 let pluginsCmdsPaths = [ ] ;
3030
3131 if ( sqz . vars . project . isValid && sqz . vars . project . plugins
3232 && sqz . vars . project . plugins . length > 0 ) {
3333 pluginsCmdsPaths = sqz . vars . project . plugins
34- . map ( ( val ) => ( `${ sqz . vars . project . path } /${ val . path } /${ val . name } /index.js` ) ) ;
34+ . map ( val => ( `${ sqz . vars . project . path } /${ val . path } /${ val . name } /index.js` ) ) ;
3535 }
3636
3737 const paths = _ . concat ( frameworkCmdsPaths , pluginsCmdsPaths ) ;
@@ -79,36 +79,50 @@ module.exports = (() => {
7979
8080 const helpCmdMsg = colors . yellow ( `\n\n$ ${ bin } ${ colors . blue . bold ( 'help' ) } ${ args . names . join ( ':' ) } ` ) ;
8181
82- _ . forEach ( cmdData . options , ( value , key ) => {
83- if ( _ . has ( args . flags , value . flag ) ) {
84- sqz . cli . params . setOption ( key , args . flags [ value . flag ] ) ;
85- }
82+ const check = ( value , key ) => {
8683 if ( value . required === true ) {
87-
8884 if ( ! _ . has ( args . options , key ) && ! _ . has ( args . flags , value . flag ) ) {
8985 sqz . cli . log . error ( `Missing option ${ colors . green ( `--${ key } ` ) } ${ helpCmdMsg } ` ) ;
9086 } else if ( ! args . options [ key ] && ! args . flags [ value . flag ] ) {
9187 sqz . cli . log . error ( `Missing option ${ colors . green ( `--${ key } ` ) } ` +
9288 `${ colors . red ( 'value' ) } ${ helpCmdMsg } ` ) ;
9389 }
94- } else {
95- if ( ! args . options [ key ] && value . defaultValue !== null ) { // eslint-disable-line no-lonely-if
96- args . options [ key ] = value . defaultValue ;
97- }
90+ } else if ( ! args . options [ key ] && value . defaultValue !== null ) {
91+ args . options [ key ] = value . defaultValue ;
9892 }
93+ } ;
9994
95+ _ . forEach ( cmdData . options , ( value , key ) => {
96+ if ( _ . has ( args . flags , value . flag ) ) {
97+ sqz . cli . params . setOption ( key , args . flags [ value . flag ] ) ;
98+ }
10099 if ( value . boolean && args . options [ key ] ) {
101100 args . options [ key ] = JSON . parse ( args . options [ key ] ) ;
102101 }
103-
104102 if ( _ . has ( value , 'validate' ) ) {
105103 if ( ! value . validate . fn ( args . options [ key ] ) ) {
106104 sqz . cli . log . error ( `${ colors . blue . bold ( `--${ key } ` ) } : ${ value . validate . error } ` ) ;
107105 }
108106 }
107+ check ( value , key ) ;
109108 } ) ;
110109 }
111110
111+ index ( args , logo ) {
112+ if ( args . names . length === 0 ) {
113+ const msg =
114+ `${ logo } \n` +
115+ `* Lists all commands ${ colors . green ( '`sqz list`' ) } .\n` +
116+ `* Get help for a command ${ colors . green ( '`sqz help [command]`' ) } .\n` +
117+ `* Add ${ colors . green ( '--debug' ) } to any command for debugging\n` +
118+ `* Squeezer framework documentation: ${ colors . cyan ( 'docs.squeezer.io' ) } \n` ;
119+
120+ sqz . cli . log . console ( msg . replace ( / ^ / gm, ' ' . repeat ( 1 ) ) ) ;
121+
122+ process . exit ( 0 ) ;
123+ }
124+ }
125+
112126 run ( ) {
113127 const args = this . args ;
114128 const command = this . commands [ args . names . join ( ':' ) ] ;
@@ -129,22 +143,11 @@ module.exports = (() => {
129143 let errorMsg = `Command "${ colors . green ( hintCmd ) } " not found ... \n` ;
130144 const availableHelpCmds = [ ] ;
131145
132- if ( args . names . length === 0 ) {
133- const msg =
134- `${ logo } \n` +
135- `* Lists all commands ${ colors . green ( '`sqz list`' ) } .\n` +
136- `* Get help for a command ${ colors . green ( '`sqz help [command]`' ) } .\n` +
137- `* Add ${ colors . green ( '--debug' ) } to any command for debugging\n` +
138- `* Squeezer framework documentation: ${ colors . cyan ( 'docs.squeezer.io' ) } \n` ;
139-
140- sqz . cli . log . console ( msg . replace ( / ^ / gm, ' ' . repeat ( 1 ) ) ) ;
141-
142- process . exit ( 0 ) ;
143- }
146+ this . index ( args , logo ) ;
144147
145148 if ( args . names [ 0 ] === 'help' && args . args . length === 0 ) {
146149 sqz . cli . log . error (
147- ` Missing help command argument , please use ` +
150+ ' Missing help command argument , please use ' +
148151 `${ colors . blue . bold ( `\`${ bin } help [command]\`` ) } ` +
149152 `\n\n... or ${ colors . blue . bold ( `\`${ bin } list\`` ) } to get all available commands\n`
150153 ) ;
@@ -155,10 +158,11 @@ module.exports = (() => {
155158 if ( cmd . indexOf ( hintCmd ) >= 0 ) {
156159 availableHelpCmds . push ( cmd ) ;
157160 }
161+ return availableHelpCmds ;
158162 } ) ;
159163
160164 if ( availableHelpCmds . length > 0 ) {
161- errorMsg += colors . green ( ` \nDid you mean one of these commands?\n\n` ) ;
165+ errorMsg += colors . green ( ' \nDid you mean one of these commands?\n\n' ) ;
162166 errorMsg += `${ ' ' . repeat ( 3 ) } ${ colors . blue . bold ( availableHelpCmds . join ( `\n${ ' ' . repeat ( 3 ) } ` ) ) } ` ;
163167 }
164168
0 commit comments