import { AwilixContainer } from 'awilix' ; import { Cache } from 'flat-cache' ; import { CommandHandler } from '../..' ; import { assertExists } from '../../utils' ; import { RunBlock } from './run.block' ; import { RunBlockRange } from './run.block.range' ; import { RunFile } from './run.file' ; import { RunLive } from './run.live' ; import { RunTransaction } from './run.transaction' ; import { RunProdServer } from './server' ; export default function provideRun ( container , cache ) { assertExists ( container , 'container' ) ; assertExists ( cache , 'cache' ) ; return async function run ( cliArgs ) { if ( cliArgs . tx ) { const runTransaction = container . resolve < RunTransaction > ( "runTransaction" ) ; await runTransaction ( cliArgs . tx ) ; } else if ( cliArgs . block ) { const runBlock = container . resolve < RunBlock > ( "runBlock" ) ; await runBlock ( cliArgs . block ) ; } else if ( cliArgs . range ) { const runBlockRange = container . resolve < RunBlockRange > ( "runBlockRange" ) ; await runBlockRange ( cliArgs . range ) ; } else if ( cliArgs . file ) { const runFile = container . resolve < RunFile > ( "runFile" ) ; await runFile ( cliArgs . file ) ; } else if ( cliArgs . prod ) { const runProdServer = container . resolve < RunProdServer > ( "runProdServer" ) ; await runProdServer ( ) ; } else { const runLive = container . resolve < RunLive > ( "runLive" ) ; await runLive ( ) ; } cache . save ( true ) ; let isShortLived = cliArgs . tx || cliArgs . block || cliArgs . range || cliArgs . file ; if ( isShortLived ) process . exit ( ) ; } ; }