@@ -18,6 +18,7 @@ type ParsedArgs = {
18
18
setupBranch : string ;
19
19
output ?: string ;
20
20
help : string ;
21
+ version ?: string ;
21
22
} ;
22
23
23
24
type Options = {
@@ -31,37 +32,6 @@ type Options = {
31
32
const localGit = "Local directory" ;
32
33
const remoteGit = "Git remote address" ;
33
34
34
- function parseArgumentsIntoOptions ( rawArgs : string [ ] ) : ParsedArgs {
35
- const args = arg (
36
- {
37
- "--git" : String ,
38
- "--dir" : String ,
39
- "--code" : String ,
40
- "--setup" : String ,
41
- "--output" : String ,
42
- "--help" : Boolean ,
43
- "-g" : "--git" ,
44
- "-d" : "--dir" ,
45
- "-c" : "--code" ,
46
- "-s" : "--setup" ,
47
- "-o" : "--output" ,
48
- "-h" : "--help" ,
49
- } ,
50
- {
51
- argv : rawArgs . slice ( 2 ) ,
52
- }
53
- ) ;
54
- return {
55
- command : args [ "_" ] [ 0 ] ,
56
- git : args [ "--git" ] ,
57
- dir : args [ "--dir" ] ,
58
- codeBranch : args [ "--code" ] ,
59
- setupBranch : args [ "--setup" ] ,
60
- output : args [ "--output" ] || "./config.json" ,
61
- help : args [ "--help" ] || false ,
62
- } ;
63
- }
64
-
65
35
export async function promptForMissingOptions (
66
36
options : ParsedArgs
67
37
) : Promise < Options > {
@@ -152,36 +122,36 @@ export async function promptForMissingOptions(
152
122
}
153
123
154
124
export async function cli ( args : string [ ] ) : Promise < void > {
155
- let parsedArgs : ParsedArgs = parseArgumentsIntoOptions ( args ) ;
156
-
157
- // If help called just print the help text and exit
158
- if ( parsedArgs . help ) {
159
- console . log (
160
- "Docs can be found at github: https://github.com/coderoad/coderoad-cli/"
161
- ) ;
162
- } else if ( ! parsedArgs . command ) {
163
- console . log (
164
- `The command is missing. Choose either 'create' or 'build' and its options.`
165
- ) ;
166
- } else {
167
- switch ( parsedArgs . command ) {
168
- case "build" :
169
- // Otherwise, continue with the other options
170
- const options : BuildOptions = await promptForMissingOptions ( parsedArgs ) ;
171
- const tutorial : T . Tutorial = await build ( options ) ;
172
-
173
- if ( tutorial ) {
174
- if ( options . output ) {
175
- fs . writeFileSync ( options . output , JSON . stringify ( tutorial ) , "utf8" ) ;
176
- } else {
177
- console . log ( JSON . stringify ( tutorial , null , 2 ) ) ;
178
- }
179
- }
180
- break ;
181
-
182
- case "create" :
183
- create ( process . cwd ( ) ) ;
184
- break ;
185
- }
125
+ const command : string = args [ 2 ] ;
126
+
127
+ switch ( command ) {
128
+ case "--version" :
129
+ case "-v" :
130
+ const version = require ( "../package.json" ) . version ;
131
+ console . log ( `v ${ version } ` ) ;
132
+ return ;
133
+ case "build" :
134
+ // Otherwise, continue with the other options
135
+ // const options: BuildOptions = await promptForMissingOptions(parsedArgs );
136
+ // const tutorial: T.Tutorial = await build(options);
137
+
138
+ // if (tutorial) {
139
+ // if ( options.output) {
140
+ // fs.writeFileSync(options.output, JSON.stringify(tutorial), "utf8" );
141
+ // } else {
142
+ // console.log(JSON.stringify(tutorial, null, 2));
143
+ // }
144
+ // }
145
+ break ;
146
+
147
+ case "create" :
148
+ create ( process . cwd ( ) ) ;
149
+ break ;
150
+ case "--help" :
151
+ case "-h" :
152
+ default :
153
+ console . log (
154
+ "Docs can be found at github: https://github.com/coderoad/coderoad-cli/"
155
+ ) ;
186
156
}
187
157
}
0 commit comments