@travetto/cli 3.4.2 → 3.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/schema.ts +19 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/cli",
3
- "version": "3.4.2",
3
+ "version": "3.4.4",
4
4
  "description": "CLI infrastructure for Travetto framework",
5
5
  "keywords": [
6
6
  "cli",
@@ -29,7 +29,7 @@
29
29
  "directory": "module/cli"
30
30
  },
31
31
  "dependencies": {
32
- "@travetto/schema": "^3.4.0",
32
+ "@travetto/schema": "^3.4.2",
33
33
  "@travetto/terminal": "^3.4.0"
34
34
  },
35
35
  "travetto": {
package/src/schema.ts CHANGED
@@ -12,17 +12,17 @@ const SHORT_FLAG = /^-[a-z]/i;
12
12
 
13
13
  type ParsedInput =
14
14
  { type: 'unknown', input: string } |
15
- { type: 'arg', input: string, array?: boolean } |
15
+ { type: 'arg', input: string, array?: boolean, index: number } |
16
16
  { type: 'flag', input: string, array?: boolean, fieldName: string, value?: unknown };
17
17
 
18
18
  const isBoolFlag = (x?: CliCommandInput): boolean => x?.type === 'boolean' && !x.array;
19
19
 
20
- const getInput = (cfg: { field?: CliCommandInput, rawText?: string, input: string, value?: string }): ParsedInput => {
21
- const { field, input, rawText = input, value } = cfg;
20
+ const getInput = (cfg: { field?: CliCommandInput, rawText?: string, input: string, index?: number, value?: string }): ParsedInput => {
21
+ const { field, input, rawText = input, value, index } = cfg;
22
22
  if (!field) {
23
23
  return { type: 'unknown', input: rawText };
24
24
  } else if (!field.flagNames?.length) {
25
- return { type: 'arg', input: field ? input : rawText ?? input, array: field.array };
25
+ return { type: 'arg', input: field ? input : rawText ?? input, array: field.array, index: index! };
26
26
  } else {
27
27
  return {
28
28
  type: 'flag',
@@ -48,7 +48,7 @@ function fieldToInput(x: FieldConfig): CliCommandInput {
48
48
  choices: x.enum?.values,
49
49
  fileExtensions: type === 'file' ? x.specifiers?.filter(s => s.startsWith('ext:')).map(s => s.split('ext:')[1]) : undefined,
50
50
  type,
51
- default: x.default,
51
+ default: Array.isArray(x.default) ? x.default.slice(0) : x.default,
52
52
  flagNames: (x.aliases ?? []).slice(0).filter(v => !v.startsWith('env.')),
53
53
  envVars: (x.aliases ?? []).slice(0).filter(v => v.startsWith('env.')).map(v => v.replace('env.', ''))
54
54
  });
@@ -183,7 +183,7 @@ export class CliCommandSchemaUtil {
183
183
  }
184
184
  } else {
185
185
  const field = schema.args[argIdx];
186
- out.push(getInput({ field, input }));
186
+ out.push(getInput({ field, input, index: argIdx }));
187
187
  // Move argIdx along if not in a vararg situation
188
188
  if (!field?.array) {
189
189
  argIdx += 1;
@@ -225,11 +225,21 @@ export class CliCommandSchemaUtil {
225
225
  /**
226
226
  * Produce the arguments into the final argument set
227
227
  */
228
- static async bindArgs(cmd: CliCommandShape, args: ParsedInput[]): Promise<unknown[]> {
228
+ static async bindArgs(cmd: CliCommandShape, inputs: ParsedInput[]): Promise<unknown[]> {
229
229
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
230
230
  const cls = cmd.constructor as Class<CliCommandShape>;
231
- const out = args.filter(x => x.type === 'arg').map(x => x.input);
232
- return BindUtil.coerceMethodParams(cls, 'main', out, true);
231
+ const bound: unknown[] = [];
232
+ for (const input of inputs) {
233
+ if (input.type === 'arg') {
234
+ if (input.array) {
235
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
236
+ ((bound[input.index] ??= []) as unknown[]).push(input.input);
237
+ } else {
238
+ bound[input.index] = input.input;
239
+ }
240
+ }
241
+ }
242
+ return BindUtil.coerceMethodParams(cls, 'main', bound);
233
243
  }
234
244
 
235
245
  /**