sim 2.2.20-preview.254.1 → 2.2.20-preview.256.1

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.
@@ -67,6 +67,11 @@ export interface FlagSpec {
67
67
  * error, and a literal `#` value can still be passed.
68
68
  */
69
69
  manifest?: true;
70
+ /**
71
+ * The list's values may also follow the command as arguments, so `files batch-delete <id>...`
72
+ * reads like `rm`. Passing both forms is refused. At most one field per command.
73
+ */
74
+ trailing?: true;
70
75
  /** Take a JSON string. Implied for object/array/unknown fields. */
71
76
  json?: boolean;
72
77
  /** Read a scalar string verbatim from `@path` / `@-`; `@@` escapes a literal leading `@`. */
@@ -232,6 +237,11 @@ export interface CommandSpec {
232
237
  command?: string;
233
238
  /** Run this operation when its top-level group is invoked without a subcommand. */
234
239
  groupDefault?: boolean;
240
+ /**
241
+ * Run this leaf when its group is named without a subcommand, as the group's default. The group
242
+ * keeps no options of its own, so the leaf parses its options in either spelling.
243
+ */
244
+ defaultSubcommand?: true;
235
245
  /** Alternate leaf command names, such as `ls` for `list`. */
236
246
  aliases?: readonly string[];
237
247
  /**
package/dist/index.js CHANGED
@@ -20138,6 +20138,7 @@ var CLI_CONTRACT = {
20138
20138
  ]
20139
20139
  },
20140
20140
  listCredentialProviders: {
20141
+ defaultSubcommand: true,
20141
20142
  columns: [
20142
20143
  { header: "type" },
20143
20144
  { header: "service", path: "serviceId" },
@@ -20211,7 +20212,7 @@ var CLI_CONTRACT = {
20211
20212
  command: "files batch-delete",
20212
20213
  describe: "Delete several files at once",
20213
20214
  flags: {
20214
- fileIds: { list: true }
20215
+ fileIds: { list: true, trailing: true }
20215
20216
  },
20216
20217
  confirm: "This archives the listed files; restore them with `files restore`."
20217
20218
  },
@@ -21352,6 +21353,9 @@ var NUMERIC_KINDS = new Set(["number", "integer"]);
21352
21353
  function flagSpecFor(operation, field) {
21353
21354
  return CLI_CONTRACT[operation]?.flags?.[field] ?? {};
21354
21355
  }
21356
+ function trailingListField(commandSpec) {
21357
+ return Object.entries(commandSpec.flags ?? {}).find(([, flag]) => flag.trailing)?.[0];
21358
+ }
21355
21359
  var RESERVED_PROGRAM_FLAGS = new Set([
21356
21360
  "--version",
21357
21361
  "-V",
@@ -21799,7 +21803,7 @@ function addFieldOption(command, operation, field, descriptor, slot, paginates,
21799
21803
  const placeholder = takesList ? "<value...>" : flag.rowCap ? "<n>" : wantsJson ? "<json|@file>" : flag.textSource ? "<value|@file>" : descriptor.nullable ? "<number|null>" : "<value>";
21800
21804
  const choices = flag.choices ?? descriptor.values;
21801
21805
  const literalNull = slot === "body" && !takesList && !wantsJson && !descriptor.nullable;
21802
- const describe = `${documented}${takesList ? flag.manifest ? " (space-separated, or @path / @- with one value per line; in a file, blank lines and # comments are ignored, while inline values are sent as typed and may not be empty; @@value for a literal leading @)" : " (space-separated, or @path / @- with one value per line; @@value for a literal leading @)" : wantsJson ? " (JSON, or @path / @- to read a file or stdin)" : flag.textSource ? " (@path / @- reads a file or stdin verbatim, including trailing newlines; @@value for a literal leading @)" : ""}${descriptor.required ? " (required)" : ""}${literalNull ? literalNullHint(documented, name) : ""}`;
21806
+ const describe = `${documented}${takesList ? flag.manifest ? " (space-separated, or @path / @- with one value per line; in a file, blank lines and # comments are ignored, while inline values are sent as typed and may not be empty; @@value for a literal leading @)" : " (space-separated, or @path / @- with one value per line; @@value for a literal leading @)" : wantsJson ? " (JSON, or @path / @- to read a file or stdin)" : flag.textSource ? " (@path / @- reads a file or stdin verbatim, including trailing newlines; @@value for a literal leading @)" : ""}${descriptor.required ? flag.trailing ? " (required, or pass the values as arguments)" : " (required)" : ""}${literalNull ? literalNullHint(documented, name) : ""}`;
21803
21807
  const renamedFrom = flag.renamedFrom ?? [];
21804
21808
  const option = new Option(`${short}--${name} ${placeholder}`, describe);
21805
21809
  if (flag.hidden)
@@ -21809,8 +21813,9 @@ function addFieldOption(command, operation, field, descriptor, slot, paginates,
21809
21813
  if (descriptor.default !== undefined && field !== "limit") {
21810
21814
  option.default(undefined, String(descriptor.default));
21811
21815
  }
21812
- if (descriptor.required && renamedFrom.length === 0)
21816
+ if (descriptor.required && renamedFrom.length === 0 && !flag.trailing) {
21813
21817
  option.makeOptionMandatory();
21818
+ }
21814
21819
  command.addOption(option);
21815
21820
  for (const previous of renamedFrom) {
21816
21821
  const retired = new Option(`--${previous} ${placeholder}`).hideHelp();
@@ -22083,6 +22088,15 @@ async function executeOperation(operation, commandSpec, operationSpec, invocatio
22083
22088
  for (const [index, field] of (commandSpec.positionals ?? []).entries()) {
22084
22089
  requestFlags[camel(flagNameFor(operation, field))] = invocation[pathPositionalCount + index];
22085
22090
  }
22091
+ const trailing = trailingListField(commandSpec);
22092
+ const trailingValues = trailing ? invocation[pathPositionalCount + (commandSpec.positionals?.length ?? 0)] : undefined;
22093
+ if (trailing && Array.isArray(trailingValues) && trailingValues.length > 0) {
22094
+ const name = flagNameFor(operation, trailing);
22095
+ if (requestFlags[camel(name)] !== undefined) {
22096
+ throw new SimApiError(`Pass the ${name} as arguments or with --${name}, not both`, 0);
22097
+ }
22098
+ requestFlags[camel(name)] = trailingValues;
22099
+ }
22086
22100
  foldRenamedFlags(operation, commandSpec, requestFlags);
22087
22101
  assertCapIsUsable(operation, requestFlags);
22088
22102
  assertSelectorIsUsable(operation, requestFlags);
@@ -22448,6 +22462,18 @@ function configureOperation(command, operation, spec) {
22448
22462
  }
22449
22463
  command.argument(`<${flagNameFor(operation, field)}>`, flagSpecFor(operation, field).describe ?? descriptor.describe);
22450
22464
  }
22465
+ const trailing = trailingListField(spec);
22466
+ if (trailing) {
22467
+ const trailingFlags = Object.values(spec.flags ?? {}).filter((flag) => flag.trailing);
22468
+ const descriptor = operationSpec.query?.[trailing] ?? operationSpec.body?.[trailing];
22469
+ if (trailingFlags.length > 1)
22470
+ throw new Error(`${operation} declares more than one trailing list`);
22471
+ if (!descriptor || !flagSpecFor(operation, trailing).list) {
22472
+ throw new Error(`${operation}.${trailing} is trailing but not a list request field`);
22473
+ }
22474
+ const name = flagNameFor(operation, trailing);
22475
+ command.argument(`[${name}...]`, `${flagSpecFor(operation, trailing).describe ?? descriptor.describe} Same as --${name}.`);
22476
+ }
22451
22477
  if (spec.requestFields) {
22452
22478
  for (const field of spec.requestFields) {
22453
22479
  if (!operationSpec.query?.[field] && !operationSpec.body?.[field] && !operationSpec.headers?.[field]) {
@@ -22526,16 +22552,21 @@ function addLeafCommand(groups, operation, spec, segments) {
22526
22552
  for (const segment of rest.slice(0, -1)) {
22527
22553
  parent = nestedGroup(parent, segment);
22528
22554
  }
22529
- parent.addCommand(buildLeaf(operation, spec, rest[rest.length - 1]));
22555
+ parent.addCommand(buildLeaf(operation, spec, rest[rest.length - 1]), {
22556
+ isDefault: spec.defaultSubcommand === true
22557
+ });
22530
22558
  return;
22531
22559
  }
22532
- group.addCommand(buildLeaf(operation, spec, rest[0]));
22560
+ group.addCommand(buildLeaf(operation, spec, rest[0]), {
22561
+ isDefault: spec.defaultSubcommand === true
22562
+ });
22533
22563
  }
22534
22564
  function variantCommandSpec(spec, variant) {
22535
22565
  return {
22536
22566
  ...spec,
22537
22567
  command: variant.command,
22538
22568
  groupDefault: false,
22569
+ defaultSubcommand: undefined,
22539
22570
  aliases: [],
22540
22571
  positionals: variant.positionals,
22541
22572
  requestFields: variant.requestFields,
@@ -34,6 +34,8 @@ export declare function isProfileWorkspacePath(commandSpec: CommandSpec, param:
34
34
  */
35
35
  export declare function cursorSlot(operationSpec: Pick<OperationSpec, 'query' | 'body'>): 'query' | 'body' | null;
36
36
  export declare function flagSpecFor(operation: V2OperationName, field: string): FlagSpec;
37
+ /** The list field whose values may also follow the command as arguments, if any. */
38
+ export declare function trailingListField(commandSpec: CommandSpec): string | undefined;
37
39
  /**
38
40
  * Long and short flags the root program has already claimed.
39
41
  *
package/dist/runtime.js CHANGED
@@ -20187,6 +20187,7 @@ var CLI_CONTRACT = {
20187
20187
  ]
20188
20188
  },
20189
20189
  listCredentialProviders: {
20190
+ defaultSubcommand: true,
20190
20191
  columns: [
20191
20192
  { header: "type" },
20192
20193
  { header: "service", path: "serviceId" },
@@ -20260,7 +20261,7 @@ var CLI_CONTRACT = {
20260
20261
  command: "files batch-delete",
20261
20262
  describe: "Delete several files at once",
20262
20263
  flags: {
20263
- fileIds: { list: true }
20264
+ fileIds: { list: true, trailing: true }
20264
20265
  },
20265
20266
  confirm: "This archives the listed files; restore them with `files restore`."
20266
20267
  },
@@ -21401,6 +21402,9 @@ var NUMERIC_KINDS = new Set(["number", "integer"]);
21401
21402
  function flagSpecFor(operation, field) {
21402
21403
  return CLI_CONTRACT[operation]?.flags?.[field] ?? {};
21403
21404
  }
21405
+ function trailingListField(commandSpec) {
21406
+ return Object.entries(commandSpec.flags ?? {}).find(([, flag]) => flag.trailing)?.[0];
21407
+ }
21404
21408
  var RESERVED_PROGRAM_FLAGS = new Set([
21405
21409
  "--version",
21406
21410
  "-V",
@@ -21848,7 +21852,7 @@ function addFieldOption(command, operation, field, descriptor, slot, paginates,
21848
21852
  const placeholder = takesList ? "<value...>" : flag.rowCap ? "<n>" : wantsJson ? "<json|@file>" : flag.textSource ? "<value|@file>" : descriptor.nullable ? "<number|null>" : "<value>";
21849
21853
  const choices = flag.choices ?? descriptor.values;
21850
21854
  const literalNull = slot === "body" && !takesList && !wantsJson && !descriptor.nullable;
21851
- const describe = `${documented}${takesList ? flag.manifest ? " (space-separated, or @path / @- with one value per line; in a file, blank lines and # comments are ignored, while inline values are sent as typed and may not be empty; @@value for a literal leading @)" : " (space-separated, or @path / @- with one value per line; @@value for a literal leading @)" : wantsJson ? " (JSON, or @path / @- to read a file or stdin)" : flag.textSource ? " (@path / @- reads a file or stdin verbatim, including trailing newlines; @@value for a literal leading @)" : ""}${descriptor.required ? " (required)" : ""}${literalNull ? literalNullHint(documented, name) : ""}`;
21855
+ const describe = `${documented}${takesList ? flag.manifest ? " (space-separated, or @path / @- with one value per line; in a file, blank lines and # comments are ignored, while inline values are sent as typed and may not be empty; @@value for a literal leading @)" : " (space-separated, or @path / @- with one value per line; @@value for a literal leading @)" : wantsJson ? " (JSON, or @path / @- to read a file or stdin)" : flag.textSource ? " (@path / @- reads a file or stdin verbatim, including trailing newlines; @@value for a literal leading @)" : ""}${descriptor.required ? flag.trailing ? " (required, or pass the values as arguments)" : " (required)" : ""}${literalNull ? literalNullHint(documented, name) : ""}`;
21852
21856
  const renamedFrom = flag.renamedFrom ?? [];
21853
21857
  const option = new Option(`${short}--${name} ${placeholder}`, describe);
21854
21858
  if (flag.hidden)
@@ -21858,8 +21862,9 @@ function addFieldOption(command, operation, field, descriptor, slot, paginates,
21858
21862
  if (descriptor.default !== undefined && field !== "limit") {
21859
21863
  option.default(undefined, String(descriptor.default));
21860
21864
  }
21861
- if (descriptor.required && renamedFrom.length === 0)
21865
+ if (descriptor.required && renamedFrom.length === 0 && !flag.trailing) {
21862
21866
  option.makeOptionMandatory();
21867
+ }
21863
21868
  command.addOption(option);
21864
21869
  for (const previous of renamedFrom) {
21865
21870
  const retired = new Option(`--${previous} ${placeholder}`).hideHelp();
@@ -22132,6 +22137,15 @@ async function executeOperation(operation, commandSpec, operationSpec, invocatio
22132
22137
  for (const [index, field] of (commandSpec.positionals ?? []).entries()) {
22133
22138
  requestFlags[camel(flagNameFor(operation, field))] = invocation[pathPositionalCount + index];
22134
22139
  }
22140
+ const trailing = trailingListField(commandSpec);
22141
+ const trailingValues = trailing ? invocation[pathPositionalCount + (commandSpec.positionals?.length ?? 0)] : undefined;
22142
+ if (trailing && Array.isArray(trailingValues) && trailingValues.length > 0) {
22143
+ const name = flagNameFor(operation, trailing);
22144
+ if (requestFlags[camel(name)] !== undefined) {
22145
+ throw new SimApiError(`Pass the ${name} as arguments or with --${name}, not both`, 0);
22146
+ }
22147
+ requestFlags[camel(name)] = trailingValues;
22148
+ }
22135
22149
  foldRenamedFlags(operation, commandSpec, requestFlags);
22136
22150
  assertCapIsUsable(operation, requestFlags);
22137
22151
  assertSelectorIsUsable(operation, requestFlags);
@@ -22497,6 +22511,18 @@ function configureOperation(command, operation, spec) {
22497
22511
  }
22498
22512
  command.argument(`<${flagNameFor(operation, field)}>`, flagSpecFor(operation, field).describe ?? descriptor.describe);
22499
22513
  }
22514
+ const trailing = trailingListField(spec);
22515
+ if (trailing) {
22516
+ const trailingFlags = Object.values(spec.flags ?? {}).filter((flag) => flag.trailing);
22517
+ const descriptor = operationSpec.query?.[trailing] ?? operationSpec.body?.[trailing];
22518
+ if (trailingFlags.length > 1)
22519
+ throw new Error(`${operation} declares more than one trailing list`);
22520
+ if (!descriptor || !flagSpecFor(operation, trailing).list) {
22521
+ throw new Error(`${operation}.${trailing} is trailing but not a list request field`);
22522
+ }
22523
+ const name = flagNameFor(operation, trailing);
22524
+ command.argument(`[${name}...]`, `${flagSpecFor(operation, trailing).describe ?? descriptor.describe} Same as --${name}.`);
22525
+ }
22500
22526
  if (spec.requestFields) {
22501
22527
  for (const field of spec.requestFields) {
22502
22528
  if (!operationSpec.query?.[field] && !operationSpec.body?.[field] && !operationSpec.headers?.[field]) {
@@ -22575,16 +22601,21 @@ function addLeafCommand(groups, operation, spec, segments) {
22575
22601
  for (const segment of rest.slice(0, -1)) {
22576
22602
  parent = nestedGroup(parent, segment);
22577
22603
  }
22578
- parent.addCommand(buildLeaf(operation, spec, rest[rest.length - 1]));
22604
+ parent.addCommand(buildLeaf(operation, spec, rest[rest.length - 1]), {
22605
+ isDefault: spec.defaultSubcommand === true
22606
+ });
22579
22607
  return;
22580
22608
  }
22581
- group.addCommand(buildLeaf(operation, spec, rest[0]));
22609
+ group.addCommand(buildLeaf(operation, spec, rest[0]), {
22610
+ isDefault: spec.defaultSubcommand === true
22611
+ });
22582
22612
  }
22583
22613
  function variantCommandSpec(spec, variant) {
22584
22614
  return {
22585
22615
  ...spec,
22586
22616
  command: variant.command,
22587
22617
  groupDefault: false,
22618
+ defaultSubcommand: undefined,
22588
22619
  aliases: [],
22589
22620
  positionals: variant.positionals,
22590
22621
  requestFields: variant.requestFields,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim",
3
- "version": "2.2.20-preview.254.1",
3
+ "version": "2.2.20-preview.256.1",
4
4
  "description": "Sim CLI - talk to the Sim API from your terminal",
5
5
  "type": "module",
6
6
  "imports": {