import { CliProgramDefinition, CliCommandDefinition, ParsedCliCommand } from '../src'; import { parseCommandLine, createProgram } from './helpers/utils'; describe('Command Case', () => { const cmdDef: CliCommandDefinition = { name: 'camelCommand', description: 'Command with camel cased name', handler: parsed => { // console.log(`running ${parsed.parsedCommandName}`); }, arguments: [ { name: 'src', description: 'Source file' }, { name: 'dest', description: 'Desination File', isOptional: true, default: 'Default Value' }, { name: 'thirdarg', description: 'Another arg', //isOptional: true, // default value should affect this as set default: 'Another Default', validate: /^(large|medium|small)$/i, }, ], options: [ { name: 'output', flag: '-o', description: 'output description', }, { name: 'transform', flag: '-t', description: 'test transform', transform: (val) => { return `tranformed:${val}` } }, { name: 'noValueType', description: 'to test for default valueType', }, { name: 'tobool', flag: '-b', description: 'test bool valuetype', valueType: 'boolean' }, { name: 'tobooldefaulttrue', flag: '-b', description: 'test bool valuetype', valueType: 'boolean', default: true }, { name: 'tostring', description: 'test string valuetype', valueType: 'string' }, { name: 'tonumber', description: 'test number valuetype', valueType: 'number' }, { name: 'validation', description: 'Validation', validate: /^(large|medium|small)$/i, valueType: 'string' }, { name: 'dashedName', description: 'Dashed Name', valueType: 'string', }, ], }; const cmdsDef = createProgram('camelDefs', cmdDef); const p1 = parseCommandLine('camelCommand a b', cmdsDef); it('Parse command with camelCased Name on exact', () => { expect(p1.command.name).toEqual('camelCommand'); expect(p1.parsedArguments['src']).toHaveProperty('value', 'a') expect(p1.parsedArguments['dest']).toHaveProperty('value', 'b') }) const p2 = parseCommandLine('camelcommand a b', cmdsDef); it('Parse command with camelCased Name on all lower', () => { expect(p2.command.name).toEqual('camelCommand'); expect(p2.parsedArguments['src']).toHaveProperty('value', 'a') expect(p2.parsedArguments['dest']).toHaveProperty('value', 'b') }) const p3 = parseCommandLine('camel-command a b', cmdsDef); it('Parse command with camelCased Name on dashed case cli', () => { expect(p3.command.name).toEqual('camelCommand'); expect(p3.parsedArguments['src']).toHaveProperty('value', 'a') expect(p3.parsedArguments['dest']).toHaveProperty('value', 'b') }) })