import type { CommandLineDescription , CommandLines } from '@tramvai/core' ; import { COMMAND_LINE_RUNNER_TOKEN } from '@tramvai/core' ; import type { ChildAppCommandLineRunner , ChildAppDiManager , ChildAppFinalConfig , } from '@tramvai/tokens-child-app' ; import type { LOGGER_TOKEN } from '@tramvai/tokens-common' ; export class CommandLineRunner implements ChildAppCommandLineRunner { private readonly log : ReturnType < typeof LOGGER_TOKEN > ; private readonly rootCommandLineRunner : typeof COMMAND_LINE_RUNNER_TOKEN ; private readonly diManager : ChildAppDiManager ; constructor ( { logger , rootCommandLineRunner , diManager , } ) { this . log = logger ( 'child-app:commandlinerunner' ) ; this . rootCommandLineRunner = rootCommandLineRunner ; this . diManager = diManager ; } async run ( type , status , config ) { const di = this . diManager . getChildDi ( config ) ; if ( ! di ) { return ; } try { const commandLineRunner = di . get ( { token : COMMAND_LINE_RUNNER_TOKEN , optional : true } ) ; if ( commandLineRunner && commandLineRunner !== this . rootCommandLineRunner ) { commandLineRunner . metricsInstance = this . rootCommandLineRunner . metricsInstance ; await commandLineRunner . run ( type , status , [ ] , di ) ; } } catch ( error ) { if ( error . code !== 'E_STUB' ) { this . log . error ( { event : 'run-failed' , error , type , status , config , } ) ; } } } }