import chalk from 'chalk'; import { Command } from 'commander'; import { pullTaskByIdOrName } from './test/pull'; export function TestActionCommand(): Command { const cmd = new Command('test') .alias('te') .description('Test actions against a local worker') .argument( 'type', 'The type of actions to be tested, e.g: pull, push, enqueue, transform', ) .option( '-i, --task-id ', 'The Task Id. At least one of Task Id or Task Name is required', ) .option( '-n, --task-name ', "The Task Name. Type '*' for all tasks. At least one of Task Id or Task Name is required", ) .option('-p, --profile-id ', 'The Profile ID.') .option( '-w, --worker-url ', 'The Worker URL. Default: http://localhost:4004', 'http://localhost:4004', ) .action(async (type, { taskId, taskName, profileId, workerUrl }) => { if (!!taskId) { console.log( `${chalk.green('✓')} Testing ${type} action for Task Id: ${taskId}`, ); } else if (!!taskName) { if (taskName === '*') { console.log( `${chalk.green('✓')} Testing ${type} action for all tasks`, ); } else { console.log( `${chalk.green('✓')} Testing ${type} action for Task Name: ${taskName}`, ); } } else { console.log( `${chalk.red('✗')} At least one of Task Id or Task Name is required`, ); return; } switch (type) { case 'pull': await pullTaskByIdOrName(taskId, taskName, profileId, workerUrl); break; default: console.log(`${chalk.red('✗')} Action ${type} is not supported`); break; } }); return cmd; }