@@ -134,7 +134,6 @@ export class Command {
134
134
}
135
135
136
136
export type Definition = {
137
- it ?: boolean ;
138
137
yes ?: boolean ;
139
138
no ?: boolean ;
140
139
} ;
@@ -180,13 +179,6 @@ export abstract class Program<
180
179
} ) ;
181
180
}
182
181
183
- if ( this . #interactive) {
184
- _command . option ( "it" , {
185
- type : "boolean" ,
186
- desc : "Execute actions interactively"
187
- } ) ;
188
- }
189
-
190
182
this . commands . add ( _command ) ;
191
183
192
184
return _command ;
@@ -283,7 +275,7 @@ export abstract class Program<
283
275
284
276
let input : U ;
285
277
286
- if ( this . isIt ( definition ) ) {
278
+ if ( this . isIt ( ) ) {
287
279
input = await this . interact ( definition ) ;
288
280
} else {
289
281
input = this . validate ( definition ) ;
@@ -292,8 +284,8 @@ export abstract class Program<
292
284
return await this . execute ( input ) ;
293
285
}
294
286
295
- isIt ( definition : T ) : boolean {
296
- return this . #interactive && ( definition . it || ! ( isTest ( ) || isCI ( ) ) ) ;
287
+ isIt ( ) : boolean {
288
+ return this . #interactive && ! ( isTest ( ) || isCI ( ) ) ;
297
289
}
298
290
299
291
abstract validate ( definition : T ) : U ;
@@ -400,13 +392,11 @@ export abstract class Program<
400
392
definition : T ,
401
393
message : string
402
394
) : Promise <
403
- typeof definition . it extends true
404
- ? boolean
405
- : typeof definition . no extends true
406
- ? false
407
- : typeof definition . yes extends true
408
- ? true
409
- : undefined
395
+ typeof definition . no extends true
396
+ ? false
397
+ : typeof definition . yes extends true
398
+ ? true
399
+ : undefined
410
400
> ;
411
401
async scanBoolean (
412
402
definition : T ,
@@ -417,20 +407,18 @@ export abstract class Program<
417
407
? false
418
408
: typeof definition . yes extends true
419
409
? true
420
- : typeof initialValue
410
+ : boolean
421
411
> ;
422
412
async scanBoolean (
423
413
definition : T ,
424
414
message : string ,
425
415
initialValue ?: boolean
426
416
) : Promise <
427
- typeof definition . it extends true
428
- ? boolean
429
- : typeof definition . no extends true
430
- ? false
431
- : typeof definition . yes extends true
432
- ? true
433
- : typeof initialValue
417
+ typeof definition . no extends true
418
+ ? false
419
+ : typeof definition . yes extends true
420
+ ? true
421
+ : typeof initialValue
434
422
> {
435
423
const value = this . getInteraction ( message ) ;
436
424
@@ -444,29 +432,25 @@ export abstract class Program<
444
432
? scanBoolean (
445
433
message ,
446
434
initialValue ,
447
- this . isIt ( definition ) ,
435
+ this . isIt ( ) ,
448
436
this . #useYes && definition . yes ,
449
437
this . #useNo && definition . no
450
438
)
451
439
: scanBoolean (
452
440
message ,
453
441
undefined ,
454
- this . isIt ( definition ) ,
442
+ this . isIt ( ) ,
455
443
this . #useYes && definition . yes ,
456
444
this . #useNo && definition . no
457
445
) ;
458
446
}
459
447
448
+ async scanString ( message : string ) : Promise < string | undefined > ;
449
+ async scanString ( message : string , initialValue : string ) : Promise < string > ;
460
450
async scanString (
461
- definition : T ,
462
- message : string
463
- ) : Promise < typeof definition . it extends true ? string : undefined > ;
464
- async scanString ( definition : T , message : string , initialValue : string ) : Promise < string > ;
465
- async scanString (
466
- definition : T ,
467
451
message : string ,
468
452
initialValue ?: string
469
- ) : Promise < typeof definition . it extends true ? string : typeof initialValue > {
453
+ ) : Promise < string | typeof initialValue > {
470
454
const value = this . getInteraction ( message ) ;
471
455
472
456
if ( value !== undefined ) {
@@ -476,27 +460,24 @@ export abstract class Program<
476
460
}
477
461
478
462
return initialValue
479
- ? scanString ( message , initialValue , this . isIt ( definition ) )
480
- : scanString ( message , undefined , this . isIt ( definition ) ) ;
463
+ ? scanString ( message , initialValue , this . isIt ( ) )
464
+ : scanString ( message , undefined , this . isIt ( ) ) ;
481
465
}
482
466
483
467
async scanChoice < V extends string > (
484
- definition : T ,
485
468
message : string ,
486
469
options : { value : string ; label : string } [ ]
487
- ) : Promise < typeof definition . it extends true ? V : undefined > ;
470
+ ) : Promise < V | undefined > ;
488
471
async scanChoice < V extends string > (
489
- definition : T ,
490
472
message : string ,
491
473
options : { value : string ; label : string } [ ] ,
492
474
initialValue : V
493
- ) : Promise < typeof definition . it extends true ? V : undefined > ;
475
+ ) : Promise < V > ;
494
476
async scanChoice < V extends string > (
495
- definition : T ,
496
477
message : string ,
497
478
options : { value : string ; label : string } [ ] ,
498
479
initialValue ?: V
499
- ) : Promise < typeof definition . it extends true ? V : typeof initialValue > {
480
+ ) : Promise < V | typeof initialValue > {
500
481
const value = this . getInteraction ( message ) ;
501
482
502
483
if ( value !== undefined ) {
@@ -509,8 +490,8 @@ export abstract class Program<
509
490
}
510
491
511
492
return initialValue
512
- ? scanChoice ( message , options , initialValue , this . isIt ( definition ) )
513
- : scanChoice ( message , options , undefined , this . isIt ( definition ) ) ;
493
+ ? scanChoice ( message , options , initialValue , this . isIt ( ) )
494
+ : scanChoice ( message , options , undefined , this . isIt ( ) ) ;
514
495
}
515
496
516
497
panic ( message : string ) : never {
0 commit comments