@@ -178,7 +178,7 @@ const getWalletFileChoices = async () => {
178
178
const execAsync = promisify ( exec ) ;
179
179
export default class Generate extends Command {
180
180
static args = {
181
- file : Args . string ( { description : 'file to read ' } ) ,
181
+ name : Args . string ( { name : 'name' , required : false , description : 'Name of the project ' } ) ,
182
182
} ;
183
183
184
184
static description = 'generate template' ;
@@ -187,19 +187,119 @@ export default class Generate extends Command {
187
187
'<%= config.bin %> <%= command.id %>' ,
188
188
] ;
189
189
190
- static flags = {
191
- // flag with a value (-n, --name=VALUE)
192
- name : Flags . string ( { char : 'n' , description : 'name to print' } ) ,
193
- // // flag with no value (-f, --force)
194
- // force: Flags.boolean({char: 'f'}),
195
- // // flag with no value (-t, --template)
196
- template : Flags . string ( { char : 't' , description : 'Template name' } ) ,
190
+ static flags = {
191
+ 'template' : Flags . string ( {
192
+ char : 't' ,
193
+ description : 'Template to use' ,
194
+ options : [ 'node-vanilla' , 'node-react' , 'node-vue' , 'node-react-todo' ] ,
195
+ multiple : false
196
+ } ) ,
197
+
198
+ 'connection-type' : Flags . string ( {
199
+ char : 'c' ,
200
+ description : 'Connection type' ,
201
+ options :[ 'basic' , 'walletPath' ] ,
202
+ multiple : false
203
+ } ) ,
204
+
205
+ 'db-username' : Flags . string ( {
206
+ description : 'Database username' ,
207
+ multiple : false
208
+ } ) ,
209
+
210
+ // basic connection flags
211
+ 'db-protocol' : Flags . string ( {
212
+ description : 'Database protocol' ,
213
+ multiple : false ,
214
+ relationships :[ {
215
+ type :'none' , flags :[
216
+ { name : 'connection-type' , when : async ( flags ) => flags [ 'connection-type' ] === 'walletPath' }
217
+ ]
218
+ }
219
+ ] } ) ,
220
+
221
+ 'db-hostname' : Flags . string ( {
222
+ description : 'Database host name' ,
223
+ multiple : false ,
224
+ relationships :[ {
225
+ type :'none' , flags :[
226
+ { name : 'connection-type' , when : async ( flags ) => flags [ 'connection-type' ] === 'walletPath' }
227
+ ]
228
+ } ]
229
+ } ) ,
230
+ 'db-port' : Flags . integer ( {
231
+ description : 'Database port number' ,
232
+ max : 65535 ,
233
+ min : 0 ,
234
+ multiple : false ,
235
+ relationships :[ {
236
+ type :'none' , flags :[
237
+ { name : 'connection-type' , when : async ( flags ) => flags [ 'connection-type' ] === 'walletPath' }
238
+ ]
239
+ }
240
+ ]
241
+ } ) ,
242
+ 'db-service-type' : Flags . string ( {
243
+ description : 'Database service type. Only can be sid or service name' ,
244
+ options : [ 'sid' , 'serviceName' ] ,
245
+ multiple : false ,
246
+ relationships :[ {
247
+ type :'none' , flags :[
248
+ { name : 'connection-type' , when : async ( flags ) => flags [ 'connection-type' ] === 'walletPath' }
249
+ ]
250
+ }
251
+ ]
252
+ } ) ,
253
+ 'db-sid' : Flags . string ( {
254
+ description : 'Database service ID, only needed if service type was sid' ,
255
+ multiple : false ,
256
+ relationships :[ {
257
+ type :'none' , flags :[
258
+ { name : 'connection-type' , when : async ( flags ) => flags [ 'connection-type' ] === 'walletPath' } ,
259
+ { name : 'db-service-type' , when : async ( flags ) => flags [ 'db-service-type' ] === 'serviceName' }
260
+ ]
261
+ }
262
+ ]
263
+ } ) ,
264
+ 'db-service-name' : Flags . string ( {
265
+ description : 'Database service name, only needed if service type was serviceName' ,
266
+ multiple : false ,
267
+ relationships :[ {
268
+ type :'none' , flags :[
269
+ { name : 'connection-type' , when : async ( flags ) => flags [ 'connection-type' ] === 'walletPath' } ,
270
+ { name : 'db-service-type' , when : async ( flags ) => flags [ 'db-service-type' ] === 'sid' }
271
+ ]
272
+ }
273
+ ]
274
+ } ) ,
275
+ 'wallet-path' : Flags . string ( {
276
+ description : 'Cloud wallet path' ,
277
+ dependsOn : [ 'connection-type' ] ,
278
+ multiple : false ,
279
+ relationships :[ {
280
+ type :'none' , flags :[
281
+ { name : 'connection-type' , when : async ( flags ) => flags [ 'connection-type' ] === 'basic' }
282
+ ]
283
+ }
284
+ ]
285
+ } )
197
286
} ;
198
287
199
288
public async run ( ) : Promise < void > {
200
289
const { args, flags } = await this . parse ( Generate ) ;
201
- const name = flags . name ? flags . name : '' ;
202
- const template = flags . template ? flags . template : '' ;
290
+ const name = args . name ?? '' ;
291
+ const template = flags [ 'template' ] ?? '' ;
292
+ const connectionType = flags [ 'connection-type' ] ?? '' ;
293
+ const databaseProtocol = flags [ 'db-protocol' ] ?? '' ;
294
+ const databaseHostName = flags [ 'db-hostname' ] ?? '' ;
295
+ const databasePort = flags [ 'db-port' ] ?. toString ( ) ?? '' ;
296
+ const databaseServiceType = flags [ 'db-service-type' ] ?? '' ;
297
+ const databaseSID = flags [ 'db-sid' ] ?? '' ;
298
+ const databaseServiceName = flags [ 'db-service-name' ] ?? '' ;
299
+ const databaseUsername = flags [ 'db-username' ] ?? '' ;
300
+
301
+ // TODO: Validate and use wallet path
302
+ const walletPathDirectory = flags [ 'wallet-path' ] ? flags [ 'wallet-path' ] : '' ;
203
303
204
304
// Ask the user for the application name.
205
305
const appName = name === '' ? await input (
@@ -247,7 +347,7 @@ export default class Generate extends Command {
247
347
) : template ;
248
348
249
349
// Ask the user for the database connection type (Either basic connection or a connection using a cloud wallet).
250
- const databaseConnectionType = await select (
350
+ const databaseConnectionType = connectionType === '' ? await select (
251
351
{
252
352
message : 'Which database connection type would you like to choose?' ,
253
353
choices : [
@@ -262,39 +362,39 @@ export default class Generate extends Command {
262
362
] ,
263
363
default : 'walletPath'
264
364
}
265
- ) ;
365
+ ) : connectionType ;
266
366
267
367
// This represents the config object that will hold all the information that the user has inputted and selected.
268
368
let configObject ;
269
369
270
370
// If the user has chosen the basic connection type, then we ask for the protocol, hostname, port and service name / SID.
271
371
if ( databaseConnectionType === 'basic' ) {
272
372
273
- const protocol = await input (
373
+ const protocol = databaseProtocol === '' ? await input (
274
374
{
275
375
message : 'What is your database protocol?' ,
276
376
default : 'tcp'
277
377
} ,
278
- ) ;
378
+ ) : databaseProtocol ;
279
379
280
- const hostname = await input (
380
+ const hostname = databaseHostName === '' ? await input (
281
381
{
282
382
message : 'What is your database hostname?' ,
283
383
default : 'localhost'
284
384
} ,
285
- ) ;
385
+ ) : databaseHostName ;
286
386
287
- const port = await input (
387
+ const port = databasePort === '' ? await input (
288
388
{
289
389
message : 'What is your database port?' ,
290
390
validate ( input ) {
291
391
return ! isNaN ( Number . parseInt ( input ) ) && isFinite ( Number . parseInt ( input ) ) ? true : 'Port can only be numbers!' ;
292
392
} ,
293
393
default : '1521'
294
394
} ,
295
- ) ;
395
+ ) : databasePort ;
296
396
297
- const serviceType = await select (
397
+ const serviceType = databaseServiceType === '' ? await select (
298
398
{
299
399
message : 'Which service type would you like to use?' ,
300
400
choices : [
@@ -308,29 +408,29 @@ export default class Generate extends Command {
308
408
}
309
409
]
310
410
}
311
- ) ;
411
+ ) : databaseServiceType ;
312
412
313
413
let serviceValue ;
314
414
315
- serviceValue = await (
316
- serviceType === 'sid'
317
- ? input (
318
- {
319
- message : 'Please input your database SID: ' ,
320
- validate ( input ) {
321
- return input . trim ( ) . length === 0 ? 'This field cannot be empty!' : true ;
322
- }
415
+ if ( serviceType === 'sid' ) {
416
+ serviceValue = databaseSID === '' ? await input (
417
+ {
418
+ message : 'Please enter your database SID: ' ,
419
+ validate ( input ) {
420
+ return input . trim ( ) . length === 0 ? 'This field cannot be empty!' : true ;
323
421
}
324
- )
325
- : input (
326
- {
327
- message : 'Please input your database service name: ' ,
328
- validate ( input ) {
329
- return input . trim ( ) . length === 0 ? 'This field cannot be empty!' : true ;
330
- }
422
+ }
423
+ ) : databaseSID ;
424
+ } else {
425
+ serviceValue = databaseServiceName === '' ? await input (
426
+ {
427
+ message : 'Please enter your database service name: ' ,
428
+ validate ( input ) {
429
+ return input . trim ( ) . length === 0 ? 'This field cannot be empty!' : true ;
331
430
}
332
- ) ) ;
333
-
431
+ }
432
+ ) : databaseServiceName ;
433
+ }
334
434
// This will be config object for the basic connection type.
335
435
configObject = {
336
436
appName,
@@ -345,7 +445,7 @@ export default class Generate extends Command {
345
445
walletPath = await input (
346
446
{
347
447
// TODO: Cannot use tab to autocomplete, cannot use ~ for $HOME
348
- message : 'Please input your Cloud Wallet Path:' ,
448
+ message : 'Please enter your Cloud Wallet Path:' ,
349
449
validate ( input ) {
350
450
return checkIfDirectoryOrZip ( input ) ;
351
451
}
@@ -359,7 +459,7 @@ export default class Generate extends Command {
359
459
const walletPassword = await password (
360
460
{
361
461
mask : true ,
362
- message : 'Please input your wallet password:' ,
462
+ message : 'Please enter your wallet password:' ,
363
463
validate ( input ) {
364
464
return input . trim ( ) . length === 0 ? 'This field cannot be empty!' : true ;
365
465
}
@@ -378,14 +478,14 @@ export default class Generate extends Command {
378
478
379
479
// Ask the user for the database connection username.
380
480
Object . assign ( configObject , {
381
- connectionUsername : await input (
481
+ connectionUsername : databaseUsername === '' ? await input (
382
482
{
383
483
message : 'What\'s your database username?' ,
384
484
validate ( input ) {
385
485
return input . trim ( ) . length === 0 ? 'This field cannot be empty!' : true ;
386
486
}
387
487
} ,
388
- )
488
+ ) : databaseUsername
389
489
} ) ;
390
490
391
491
// Ask the user for the database connection password.
0 commit comments