|
7 | 7 | * |
8 | 8 | */ |
9 | 9 | import { strings } from '@angular-devkit/core'; |
10 | | -import { Arguments, Option, Value } from './interface'; |
| 10 | +import { Arguments, Option, OptionType, Value } from './interface'; |
11 | 11 |
|
12 | 12 |
|
13 | | -function _coerceType(str: string | undefined, type: string, v?: Value): Value | undefined { |
| 13 | +function _coerceType(str: string | undefined, type: OptionType, v?: Value): Value | undefined { |
14 | 14 | switch (type) { |
15 | 15 | case 'any': |
16 | 16 | if (Array.isArray(v)) { |
17 | 17 | return v.concat(str || ''); |
18 | 18 | } |
19 | 19 |
|
20 | | - return _coerceType(str, 'boolean', v) !== undefined ? _coerceType(str, 'boolean', v) |
21 | | - : _coerceType(str, 'number', v) !== undefined ? _coerceType(str, 'number', v) |
22 | | - : _coerceType(str, 'string', v); |
| 20 | + return _coerceType(str, OptionType.Boolean, v) !== undefined |
| 21 | + ? _coerceType(str, OptionType.Boolean, v) |
| 22 | + : _coerceType(str, OptionType.Number, v) !== undefined |
| 23 | + ? _coerceType(str, OptionType.Number, v) |
| 24 | + : _coerceType(str, OptionType.String, v); |
23 | 25 |
|
24 | 26 | case 'string': |
25 | 27 | return str || ''; |
@@ -56,7 +58,13 @@ function _coerceType(str: string | undefined, type: string, v?: Value): Value | |
56 | 58 | } |
57 | 59 |
|
58 | 60 | function _coerce(str: string | undefined, o: Option | null, v?: Value): Value | undefined { |
59 | | - return _coerceType(str, o ? o.type : 'any', v); |
| 61 | + if (!o) { |
| 62 | + return _coerceType(str, OptionType.Any, v); |
| 63 | + } else if (o.type == 'suboption') { |
| 64 | + return _coerceType(str, OptionType.String, v); |
| 65 | + } else { |
| 66 | + return _coerceType(str, o.type, v); |
| 67 | + } |
60 | 68 | } |
61 | 69 |
|
62 | 70 |
|
|
0 commit comments