import { pick } from 'lodash' ; import { LogLevel } from '../../lib/utils/create_logger' ; import { RunCliFlags } from '../run' ; import { intervalToMs } from './interval_to_ms' ; export function parseRunCliFlags ( flags ) { const { file , _ , logLevel , interval , bucketSize } = flags ; const parsedFile = String ( file || _ [ 0 ] ) ; let parsedLogLevel = LogLevel . info ; switch ( logLevel ) { case 'trace' : parsedLogLevel = LogLevel . trace ; break ; case 'info' : parsedLogLevel = LogLevel . info ; break ; case 'debug' : parsedLogLevel = LogLevel . debug ; break ; case 'error' : parsedLogLevel = LogLevel . error ; break ; } const intervalInMs = intervalToMs ( interval ) ; if ( ! intervalInMs ) { throw new Error ( 'Invalid interval' ) ; } const bucketSizeInMs = intervalToMs ( bucketSize ) ; if ( ! bucketSizeInMs ) { throw new Error ( 'Invalid bucket size' ) ; } return { ... pick ( flags , 'target' , 'workers' , 'clientWorkers' , 'batchSize' , 'writeTarget' , 'scenarioOpts' ) , intervalInMs , bucketSizeInMs , logLevel : parsedLogLevel , file : parsedFile , } ; } export type RunOptions = ReturnType < typeof parseRunCliFlags > ;