|
1 | 1 | import { MockConsole } from 'ts-jasmine-spies'; |
2 | 2 | import { MockCommand } from '../mock/mock-command'; |
3 | 3 | import { CommandHelp } from '../../src/command-help'; |
| 4 | +import { CommandOption, OptionType } from '../../src/command-options'; |
4 | 5 |
|
5 | 6 | class HelpTestCommand extends MockCommand { |
6 | 7 | override key = 'test'; |
7 | 8 | override description = 'Test command description'; |
8 | 9 |
|
9 | | - override positional = [ |
| 10 | + override positional: CommandOption[] = [ |
10 | 11 | { key: 'arg1', description: 'First argument' }, |
11 | 12 | { key: 'arg2', description: 'Second argument' }, |
12 | 13 | ]; |
13 | 14 |
|
14 | | - override options = [ |
| 15 | + override options: CommandOption[] = [ |
15 | 16 | { key: 'opt1', description: 'First option', alias: 'o' }, |
16 | 17 | { key: 'opt2', description: 'Second option', alias: undefined }, |
17 | 18 | ]; |
@@ -53,7 +54,85 @@ describe('CommandHelp', () => { |
53 | 54 | it('can show optional arguments', () => { |
54 | 55 | commandHelp.showOptions(); |
55 | 56 | mockConsole.expectStdout( |
56 | | - ' --opt1 -o: First option\n --opt2: Second option\n' |
| 57 | + ' -o, --opt1: First option\n --opt2: Second option\n' |
| 58 | + ); |
| 59 | + }); |
| 60 | + |
| 61 | + it('shows option default value', () => { |
| 62 | + mockCommand.options = [ |
| 63 | + { |
| 64 | + key: 'opt1', |
| 65 | + description: 'First option', |
| 66 | + default: 'defaultValue', |
| 67 | + }, |
| 68 | + ]; |
| 69 | + |
| 70 | + commandHelp.showOptions(); |
| 71 | + mockConsole.expectStdout( |
| 72 | + ' --opt1: First option (default: defaultValue)\n' |
| 73 | + ); |
| 74 | + }); |
| 75 | + |
| 76 | + it('can show option without description', () => { |
| 77 | + mockCommand.options = [{ key: 'opt1', default: 'defaultValue' }]; |
| 78 | + commandHelp.showOptions(); |
| 79 | + mockConsole.expectStdout(' --opt1: (default: defaultValue)\n'); |
| 80 | + }); |
| 81 | + |
| 82 | + it('shows option choices', () => { |
| 83 | + mockCommand.options = [ |
| 84 | + { |
| 85 | + key: 'opt1', |
| 86 | + description: 'First option', |
| 87 | + choices: ['choice1', 'choice2'], |
| 88 | + }, |
| 89 | + ]; |
| 90 | + |
| 91 | + commandHelp.showOptions(); |
| 92 | + mockConsole.expectStdout( |
| 93 | + ' --opt1: First option [choices: choice1, choice2]\n' |
| 94 | + ); |
| 95 | + }); |
| 96 | + |
| 97 | + it('shows option type', () => { |
| 98 | + mockCommand.options = [ |
| 99 | + { |
| 100 | + key: 'opt1', |
| 101 | + description: 'First option', |
| 102 | + type: OptionType.number, |
| 103 | + }, |
| 104 | + ]; |
| 105 | + |
| 106 | + commandHelp.showOptions(); |
| 107 | + mockConsole.expectStdout(' --opt1: First option {number}\n'); |
| 108 | + }); |
| 109 | + |
| 110 | + it('shows skips option type for strings', () => { |
| 111 | + mockCommand.options = [ |
| 112 | + { |
| 113 | + key: 'opt1', |
| 114 | + description: 'First option', |
| 115 | + }, |
| 116 | + ]; |
| 117 | + |
| 118 | + commandHelp.showOptions(); |
| 119 | + mockConsole.expectStdout(' --opt1: First option\n'); |
| 120 | + }); |
| 121 | + |
| 122 | + it('shows default value and choices', () => { |
| 123 | + mockCommand.options = [ |
| 124 | + { |
| 125 | + key: 'opt1', |
| 126 | + description: 'First option', |
| 127 | + default: 'defaultValue', |
| 128 | + choices: ['choice1', 'choice2'], |
| 129 | + type: OptionType.string, |
| 130 | + }, |
| 131 | + ]; |
| 132 | + commandHelp.showOptions(); |
| 133 | + mockConsole.expectStdout( |
| 134 | + ' --opt1: First option (default: defaultValue)' + |
| 135 | + ' [choices: choice1, choice2]\n' |
57 | 136 | ); |
58 | 137 | }); |
59 | 138 |
|
|
0 commit comments