import { CliProgramDefinition, CliCommandDefinition, ParsedCliCommand } from '../src'; import { parseCommandLine, createProgram } from './helpers/utils'; describe('Transform Command', () => { const buildCmdDef: CliCommandDefinition = { name: 'build', description: 'my description', handler: parsed => { // console.log(`running ${parsed.parsedCommandName}`); }, arguments: [ { name: 'src', description: 'Source file' }, { name: 'dest', description: 'Desination File', isOptional: true, default: 'Default Value' }, ], options: [ { name: 'output', flag: '-o', description: 'output description', }, ], transformArguments: (args) => { return { ...args, ...{ newval: 1 }} }, transformOptions: (options) => { //return { ...options, ...{ newval: 1 }} options['newval'] = 1; return options; } }; const def = createProgram('test1', buildCmdDef); const p1 = parseCommandLine('build a b', def); it('Transform Arguments', () => { expect(p1.command.name).toEqual('build'); expect(p1.command.description).toEqual('my description'); expect(p1.parsedCommandName).toEqual('build'); expect(p1.arguments).toMatchObject({ src: 'a', dest: 'b', newval: 1 }); }) it('Transform Options', () => { expect(p1.options).toMatchObject({ output: undefined, newval: 1 }); }) })