@@ -6,8 +6,26 @@ const fs = require("fs");
6
6
const path = require ( "path" ) ;
7
7
const colors = require ( "../cli/util/colors" ) ;
8
8
const version = require ( "../package.json" ) . version ;
9
+ const options = require ( "../cli/util/options" ) ;
9
10
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 ( ) ;
11
29
12
30
function printHelp ( ) {
13
31
console . log ( [
@@ -19,12 +37,7 @@ function printHelp() {
19
37
process . exit ( 0 ) ;
20
38
}
21
39
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 ] ) ;
28
41
const compilerDir = path . join ( __dirname , ".." ) ;
29
42
const compilerVersion = require ( path . join ( compilerDir , "package.json" ) ) . version ;
30
43
const assemblyDir = path . join ( projectDir , "assembly" ) ;
@@ -75,7 +88,7 @@ console.log([
75
88
""
76
89
] . join ( "\n" ) ) ;
77
90
78
- rl . question ( colors . white ( "Do you want to proceed?" ) + " [Y/n] " , answer => {
91
+ function createProject ( answer ) {
79
92
if ( ! / ^ y ? $ / i. test ( answer ) ) {
80
93
process . exit ( 1 ) ;
81
94
return ;
@@ -132,8 +145,20 @@ rl.question(colors.white("Do you want to proceed?") + " [Y/n] ", answer => {
132
145
"" ,
133
146
"Have a nice day!"
134
147
] . 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
+ }
137
162
138
163
function ensureProjectDirectory ( ) {
139
164
console . log ( "- Making sure that the project directory exists..." ) ;
0 commit comments