@@ -40,7 +40,6 @@ import {
40
40
CommandHandlerWithEvents ,
41
41
EvaluatorArgs as Arguments ,
42
42
ExecType ,
43
- EvaluatorArgs ,
44
43
KResponse ,
45
44
ParsedOptions ,
46
45
YargsParserFlags
@@ -310,7 +309,7 @@ class InProcessExecutor implements Executor {
310
309
private async execUnsafe < T extends KResponse , O extends ParsedOptions > (
311
310
commandUntrimmed : string ,
312
311
execOptions = emptyExecOptions ( )
313
- ) : Promise < T | CodedError < number > | HTMLElement | CommandEvaluationError > {
312
+ ) : Promise < T | CodedError < number > | HTMLElement | MixedResponse | CommandEvaluationError > {
314
313
//
315
314
const tab = execOptions . tab || getCurrentTab ( )
316
315
@@ -407,48 +406,54 @@ class InProcessExecutor implements Executor {
407
406
createOutputStream : execOptions . createOutputStream || ( ( ) => this . makeStream ( getTabId ( tab ) , execUUID ) )
408
407
}
409
408
410
- let response : T | Promise < T >
411
- try {
412
- response = await Promise . resolve (
413
- currentEvaluatorImpl . apply < T , O > ( commandUntrimmed , execOptions , evaluator , args )
414
- ) . then ( response => {
415
- // indicate that the command was successfuly completed
416
- evaluator . success ( {
417
- tab,
418
- type : ( execOptions && execOptions . type ) || ExecType . TopLevel ,
419
- isDrilldown : execOptions . isDrilldown ,
420
- command,
421
- parsedOptions
422
- } )
409
+ let response : T | Promise < T > | MixedResponse
423
410
424
- return response
425
- } )
426
- } catch ( err ) {
427
- evaluator . error ( command , tab , execType , err )
428
- if ( execType === ExecType . Nested ) {
429
- throw err
411
+ const commands = command . split ( / \s * ; \s * / )
412
+ if ( commands . length > 1 ) {
413
+ response = await semicolonInvoke ( commands , execOptions )
414
+ } else {
415
+ try {
416
+ response = await Promise . resolve (
417
+ currentEvaluatorImpl . apply < T , O > ( commandUntrimmed , execOptions , evaluator , args )
418
+ ) . then ( response => {
419
+ // indicate that the command was successfuly completed
420
+ evaluator . success ( {
421
+ tab,
422
+ type : ( execOptions && execOptions . type ) || ExecType . TopLevel ,
423
+ isDrilldown : execOptions . isDrilldown ,
424
+ command,
425
+ parsedOptions
426
+ } )
427
+
428
+ return response
429
+ } )
430
+ } catch ( err ) {
431
+ evaluator . error ( command , tab , execType , err )
432
+ if ( execType === ExecType . Nested ) {
433
+ throw err
434
+ }
435
+ response = err
430
436
}
431
- response = err
432
- }
433
437
434
- if ( evaluator . options . viewTransformer && execType !== ExecType . Nested ) {
435
- response = await Promise . resolve ( response )
436
- . then ( async _ => {
437
- const maybeAView = await evaluator . options . viewTransformer ( args , _ )
438
- return maybeAView || _
439
- } )
440
- . catch ( err => {
441
- // view transformer failed; treat this as the response to the user
442
- return err
443
- } )
444
- }
438
+ if ( evaluator . options . viewTransformer && execType !== ExecType . Nested ) {
439
+ response = await Promise . resolve ( response )
440
+ . then ( async _ => {
441
+ const maybeAView = await evaluator . options . viewTransformer ( args , _ )
442
+ return maybeAView || _
443
+ } )
444
+ . catch ( err => {
445
+ // view transformer failed; treat this as the response to the user
446
+ return err
447
+ } )
448
+ }
445
449
446
- // the || true part is a safeguard for cases where typescript
447
- // didn't catch a command handler returning nothing; it
448
- // shouldn't happen, but probably isn't a sign of a dire
449
- // problem. issue a debug warning, in any case
450
- if ( ! response ) {
451
- debug ( 'warning: command handler returned nothing' , commandUntrimmed )
450
+ // the || true part is a safeguard for cases where typescript
451
+ // didn't catch a command handler returning nothing; it
452
+ // shouldn't happen, but probably isn't a sign of a dire
453
+ // problem. issue a debug warning, in any case
454
+ if ( ! response ) {
455
+ debug ( 'warning: command handler returned nothing' , commandUntrimmed )
456
+ }
452
457
}
453
458
454
459
this . emitCompletionEvent (
@@ -480,7 +485,7 @@ class InProcessExecutor implements Executor {
480
485
public async exec < T extends KResponse , O extends ParsedOptions > (
481
486
commandUntrimmed : string ,
482
487
execOptions = emptyExecOptions ( )
483
- ) : Promise < T | CodedError < number > | HTMLElement | CommandEvaluationError > {
488
+ ) : Promise < T | CodedError < number > | HTMLElement | MixedResponse | CommandEvaluationError > {
484
489
try {
485
490
return await this . execUnsafe ( commandUntrimmed , execOptions )
486
491
} catch ( err ) {
@@ -623,39 +628,36 @@ export const setExecutorImpl = (impl: Executor): void => {
623
628
* split separately
624
629
*
625
630
*/
626
- export async function semicolonInvoke ( opts : EvaluatorArgs ) : Promise < MixedResponse > {
627
- const commands = opts . command . split ( / \s * ; \s * / )
628
- if ( commands . length > 1 ) {
629
- debug ( 'semicolonInvoke' , commands )
631
+ async function semicolonInvoke ( commands : string [ ] , execOptions : ExecOptions ) : Promise < MixedResponse > {
632
+ debug ( 'semicolonInvoke' , commands )
630
633
631
- const nonEmptyCommands = commands . filter ( _ => _ )
634
+ const nonEmptyCommands = commands . filter ( _ => _ )
632
635
633
- const result : MixedResponse = await promiseEach ( nonEmptyCommands , async command => {
634
- const entity = await qexec < MixedResponsePart | true > (
635
- command ,
636
- undefined ,
637
- undefined ,
638
- Object . assign ( { } , opts . execOptions , { quiet : false , /* block, */ execUUID : opts . execOptions . execUUID } )
639
- )
636
+ const result : MixedResponse = await promiseEach ( nonEmptyCommands , async command => {
637
+ const entity = await qexec < MixedResponsePart | true > (
638
+ command ,
639
+ undefined ,
640
+ undefined ,
641
+ Object . assign ( { } , execOptions , { quiet : false , /* block, */ execUUID : execOptions . execUUID } )
642
+ )
640
643
641
- if ( entity === true ) {
642
- // pty output
643
- return ''
644
- } else {
645
- return entity
646
- }
647
- } )
644
+ if ( entity === true ) {
645
+ // pty output
646
+ return ''
647
+ } else {
648
+ return entity
649
+ }
650
+ } )
648
651
649
- return result
650
- }
652
+ return result
651
653
}
652
654
653
655
/**
654
656
* @return an instance that obeys the REPL interface
655
657
*
656
658
*/
657
659
export function getImpl ( tab : Tab ) : REPL {
658
- const impl = { qexec, rexec, pexec, click, semicolonInvoke , encodeComponent, split } as REPL
660
+ const impl = { qexec, rexec, pexec, click, encodeComponent, split } as REPL
659
661
tab . REPL = impl
660
662
return impl
661
663
}
0 commit comments