@@ -6,8 +6,26 @@ const fs = require("fs");
66const path = require ( "path" ) ;
77const colors = require ( "../cli/util/colors" ) ;
88const version = require ( "../package.json" ) . version ;
9+ const options = require ( "../cli/util/options" ) ;
910
10- if ( process . argv . length != 3 || process . argv [ 2 ] == "--help" || process . argv [ 2 ] == "-h" ) printHelp ( ) ;
11+ const asinitOptions = {
12+ "help" : {
13+ "category" : "General" ,
14+ "description" : "Prints a help message." ,
15+ "type" : "b" ,
16+ "alias" : "h"
17+ } ,
18+ "yes" : {
19+ "category" : "General" ,
20+ "description" : "Answers all questions with their default option for non-interactive usage." ,
21+ "type" : "b" ,
22+ "alias" : "y"
23+ }
24+ } ;
25+
26+ const cliOptions = options . parse ( process . argv . slice ( 2 ) , asinitOptions ) ;
27+
28+ if ( cliOptions . options . help || cliOptions . arguments . length === 0 ) printHelp ( ) ;
1129
1230function printHelp ( ) {
1331 console . log ( [
@@ -19,12 +37,7 @@ function printHelp() {
1937 process . exit ( 0 ) ;
2038}
2139
22- const rl = require ( "readline" ) . createInterface ( {
23- input : process . stdin ,
24- output : process . stdout
25- } ) ;
26-
27- const projectDir = path . resolve ( process . argv [ 2 ] ) ;
40+ const projectDir = path . resolve ( cliOptions . arguments [ 0 ] ) ;
2841const compilerDir = path . join ( __dirname , ".." ) ;
2942const compilerVersion = require ( path . join ( compilerDir , "package.json" ) ) . version ;
3043const assemblyDir = path . join ( projectDir , "assembly" ) ;
@@ -75,7 +88,7 @@ console.log([
7588 ""
7689] . join ( "\n" ) ) ;
7790
78- rl . question ( colors . white ( "Do you want to proceed?" ) + " [Y/n] " , answer => {
91+ function createProject ( answer ) {
7992 if ( ! / ^ y ? $ / i. test ( answer ) ) {
8093 process . exit ( 1 ) ;
8194 return ;
@@ -132,8 +145,20 @@ rl.question(colors.white("Do you want to proceed?") + " [Y/n] ", answer => {
132145 "" ,
133146 "Have a nice day!"
134147 ] . join ( "\n" ) ) ;
135- rl . close ( ) ;
136- } ) ;
148+ }
149+
150+ if ( cliOptions . options . yes ) {
151+ createProject ( "y" ) ;
152+ } else {
153+ const rl = require ( "readline" ) . createInterface ( {
154+ input : process . stdin ,
155+ output : process . stdout
156+ } ) ;
157+ rl . question ( colors . white ( "Do you want to proceed?" ) + " [Y/n] " , result => {
158+ rl . close ( ) ;
159+ createProject ( result ) ;
160+ } ) ;
161+ }
137162
138163function ensureProjectDirectory ( ) {
139164 console . log ( "- Making sure that the project directory exists..." ) ;
0 commit comments