import { CliCommandDefinition, CliCommandHandler, CliParsedCommandHandler, CliProgramDefinition, ParsedCliCommand } from '../src'; import { createProgram, parseCommandLine } from './helpers/utils'; describe('Unkown Commands', () => { const buildCmdDef: CliCommandDefinition = { name: 'build', description: 'my description', arguments: [ { name: 'src', description: 'Source file' }, { name: 'dest', description: 'Desination File', isOptional: true, default: 'Default Value' }, ], options: [ { name: 'output', flag: '-o', description: 'output description', }, ], }; const program = createProgram('test1', buildCmdDef); const p1 = parseCommandLine('biuld', program); it('should have a single command error for unkown command', () => { expect(p1.errors.commandErrors).toHaveLength(1); }) it('should suggest the build command for a similar unkown name', () => { expect(p1.errors.unknownCommandSuggestions[0]).toEqual('build'); }) const buildCmdDefWithDefaultAndNoArgs: CliCommandDefinition = { name: 'build', description: 'my description', arguments: [], options: [ { name: 'output', flag: '-o', description: 'output description', }, ], }; const programWithDefaultNoArgs = createProgram('test1', buildCmdDefWithDefaultAndNoArgs, 'build'); const p2 = parseCommandLine('biuld', programWithDefaultNoArgs); it('should suggest the build command for a similar unkown name, when there is a default command with no arguments', () => { expect(p2.errors.unknownCommandSuggestions).toHaveLength(1); expect(p2.errors.unknownCommandSuggestions[0]).toEqual('build'); }) const programWithDefaultAndArgs = createProgram('test1', buildCmdDef, 'build'); const p3 = parseCommandLine('biuld', programWithDefaultAndArgs); it('should not suggest default command with similar mis-spelled cli arg when default command has args (since mis-spelled cli could be arg)', () => { expect(p3.errors.unknownCommandSuggestions).toHaveLength(0); }) })