@atlaskit/ads-cli 0.5.0 → 0.7.0

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.
package/dist/esm/cli.js CHANGED
@@ -1,3 +1,4 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
1
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
3
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
4
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
@@ -27,7 +28,9 @@ import { runTool } from './commands/run-tool';
27
28
  import { createErrorEnvelope } from './envelope/create-error-envelope';
28
29
  import { createSuccessEnvelope } from './envelope/create-success-envelope';
29
30
  import { createDocSearchResults } from './output/create-doc-search-results';
31
+ import { isDisambiguation } from './output/disambiguation';
30
32
  import { formatGroupedResults } from './output/format-grouped-results';
33
+ import { formatHumanResult } from './output/format-human-result';
31
34
  import { formatCompactResults } from './output/format-results';
32
35
  import { writeHumanError } from './output/write-human-error';
33
36
  import { writeHumanResult } from './output/write-human-result';
@@ -63,6 +66,12 @@ var buildHelpText = function buildHelpText(invocation) {
63
66
  var examples = [{
64
67
  command: 'search contrast',
65
68
  comment: 'unified: components, tokens, icons & docs'
69
+ }, {
70
+ command: 'batch --command search button --type icon --command token space.200',
71
+ comment: 'canonical tokenized batch form'
72
+ }, {
73
+ command: 'batch --command "search button" --type icon --command "token space.200"',
74
+ comment: 'complete-string compatibility form'
66
75
  }, {
67
76
  command: 'search button --type component'
68
77
  }, {
@@ -155,7 +164,19 @@ var runRegistryCommand = /*#__PURE__*/function () {
155
164
  invocation: invocation
156
165
  }));
157
166
  case 2:
158
- _context2.next = 3;
167
+ if (!resolved.batch) {
168
+ _context2.next = 3;
169
+ break;
170
+ }
171
+ return _context2.abrupt("return", runBatchRequests({
172
+ command: command,
173
+ requests: resolved.batch,
174
+ json: json,
175
+ writer: writer,
176
+ invocation: invocation
177
+ }));
178
+ case 3:
179
+ _context2.next = 4;
159
180
  return Promise.all(resolved.tools.map( /*#__PURE__*/function () {
160
181
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(tool) {
161
182
  var handler, _t, _t2;
@@ -190,10 +211,10 @@ var runRegistryCommand = /*#__PURE__*/function () {
190
211
  return _ref5.apply(this, arguments);
191
212
  };
192
213
  }()));
193
- case 3:
214
+ case 4:
194
215
  results = _context2.sent;
195
216
  if (!resolved.grouped) {
196
- _context2.next = 4;
217
+ _context2.next = 5;
197
218
  break;
198
219
  }
199
220
  return _context2.abrupt("return", renderGroupedResult({
@@ -205,7 +226,7 @@ var runRegistryCommand = /*#__PURE__*/function () {
205
226
  writer: writer,
206
227
  invocation: invocation
207
228
  }));
208
- case 4:
229
+ case 5:
209
230
  return _context2.abrupt("return", renderSingleResult({
210
231
  command: command,
211
232
  input: input,
@@ -215,7 +236,7 @@ var runRegistryCommand = /*#__PURE__*/function () {
215
236
  writer: writer,
216
237
  invocation: invocation
217
238
  }));
218
- case 5:
239
+ case 6:
219
240
  case "end":
220
241
  return _context2.stop();
221
242
  }
@@ -227,17 +248,45 @@ var runRegistryCommand = /*#__PURE__*/function () {
227
248
  }();
228
249
 
229
250
  /**
230
- * Render a single-tool command result (the common case).
251
+ * Render a command's already-transformed payload as human-readable text.
252
+ *
253
+ * Tried in order:
254
+ * 1. Compact per-row view when the command declares a result kind (search/list).
255
+ * 2. The command's own `formatHuman` renderer for rich single-object payloads
256
+ * (component docs, a11y/migration guides, lint-rule markdown).
257
+ *
258
+ * Returns `null` when neither step applies, leaving the caller to choose its own last-resort
259
+ * fallback. Shared by the single-command path and `batch` so the two cannot drift apart.
231
260
  */
232
- var renderSingleResult = function renderSingleResult(_ref6) {
261
+ var formatCommandHuman = function formatCommandHuman(_ref6) {
233
262
  var _command$resultKind, _ref7, _command$formatHuman;
234
263
  var command = _ref6.command,
235
264
  input = _ref6.input,
236
- result = _ref6.result,
237
- meta = _ref6.meta,
238
- json = _ref6.json,
239
- writer = _ref6.writer,
265
+ data = _ref6.data,
240
266
  invocation = _ref6.invocation;
267
+ var resultKind = (_command$resultKind = command.resultKind) === null || _command$resultKind === void 0 ? void 0 : _command$resultKind.call(command, input);
268
+ var compact = resultKind ? formatCompactResults({
269
+ kind: resultKind,
270
+ data: data,
271
+ showFollowUp: command.name === 'search',
272
+ invocation: invocation
273
+ }) : null;
274
+ return (_ref7 = compact !== null && compact !== void 0 ? compact : (_command$formatHuman = command.formatHuman) === null || _command$formatHuman === void 0 ? void 0 : _command$formatHuman.call(command, data, {
275
+ invocation: invocation
276
+ })) !== null && _ref7 !== void 0 ? _ref7 : null;
277
+ };
278
+
279
+ /**
280
+ * Render a single-tool command result (the common case).
281
+ */
282
+ var renderSingleResult = function renderSingleResult(_ref8) {
283
+ var command = _ref8.command,
284
+ input = _ref8.input,
285
+ result = _ref8.result,
286
+ meta = _ref8.meta,
287
+ json = _ref8.json,
288
+ writer = _ref8.writer,
289
+ invocation = _ref8.invocation;
241
290
  var isError = result.isError;
242
291
 
243
292
  // The ADS search tools return an `Error: No … found` text block when nothing matches.
@@ -303,22 +352,14 @@ var renderSingleResult = function renderSingleResult(_ref6) {
303
352
  return ExitCode.Ok;
304
353
  }
305
354
 
306
- // Default (human) output, tried in order:
307
- // 1. Compact per-row view when the command declares a result kind (search/list).
308
- // 2. The command's own `formatHuman` renderer for rich single-object payloads
309
- // (component docs, a11y/migration guides, lint-rule markdown).
310
- // 3. The generic fallback: verbatim strings (e.g. foundations markdown) or pretty JSON.
311
- // Each step returns `null` to defer to the next, so a raw JSON dump is only ever a last resort.
312
- var resultKind = (_command$resultKind = command.resultKind) === null || _command$resultKind === void 0 ? void 0 : _command$resultKind.call(command, input);
313
- var compact = resultKind ? formatCompactResults({
314
- kind: resultKind,
355
+ // Default (human) output: the shared renderer, falling back to verbatim strings (e.g.
356
+ // foundations markdown) or pretty JSON so a raw dump is only ever a last resort.
357
+ var human = formatCommandHuman({
358
+ command: command,
359
+ input: input,
315
360
  data: data,
316
- showFollowUp: command.name === 'search',
317
- invocation: invocation
318
- }) : null;
319
- var human = (_ref7 = compact !== null && compact !== void 0 ? compact : (_command$formatHuman = command.formatHuman) === null || _command$formatHuman === void 0 ? void 0 : _command$formatHuman.call(command, data, {
320
361
  invocation: invocation
321
- })) !== null && _ref7 !== void 0 ? _ref7 : null;
362
+ });
322
363
  if (human !== null) {
323
364
  writer.out(human);
324
365
  } else {
@@ -329,6 +370,209 @@ var renderSingleResult = function renderSingleResult(_ref6) {
329
370
  }
330
371
  return ExitCode.Ok;
331
372
  };
373
+ var classifyBatchResponse = function classifyBatchResponse(response) {
374
+ if (!response.ok) {
375
+ return 'failure';
376
+ }
377
+ return isDisambiguation(response.data) ? 'ambiguous' : 'success';
378
+ };
379
+ var createCapturedWriter = function createCapturedWriter() {
380
+ var stdout = [];
381
+ var stderr = [];
382
+ return {
383
+ stdout: stdout,
384
+ stderr: stderr,
385
+ out: function out(line) {
386
+ return stdout.push(line);
387
+ },
388
+ err: function err(line) {
389
+ return stderr.push(line);
390
+ }
391
+ };
392
+ };
393
+
394
+ /**
395
+ * Execute one child argv through the normal CLI pipeline, forcing JSON so the parent can preserve
396
+ * the child's stable envelope without scraping human-readable output.
397
+ *
398
+ * There is deliberately no `--help`/`--version` guard here. Every child token is also a top-level
399
+ * token, so {@link run} already short-circuits the whole invocation to help/version text before a
400
+ * batch is ever resolved — a guard at this level would be unreachable.
401
+ */
402
+ var runBatchChild = /*#__PURE__*/function () {
403
+ var _ref0 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref9) {
404
+ var request, invocation, parsed, response, captured;
405
+ return _regeneratorRuntime.wrap(function (_context3) {
406
+ while (1) switch (_context3.prev = _context3.next) {
407
+ case 0:
408
+ request = _ref9.request, invocation = _ref9.invocation;
409
+ parsed = parseArgs(request.argv);
410
+ if (parsed.command) {
411
+ _context3.next = 1;
412
+ break;
413
+ }
414
+ response = createErrorEnvelope({
415
+ command: 'batch',
416
+ code: 'USAGE_ERROR',
417
+ message: 'A batch request must start with a command name.'
418
+ });
419
+ _context3.next = 4;
420
+ break;
421
+ case 1:
422
+ if (!(parsed.command === 'batch')) {
423
+ _context3.next = 2;
424
+ break;
425
+ }
426
+ response = createErrorEnvelope({
427
+ command: 'batch',
428
+ code: 'USAGE_ERROR',
429
+ message: 'Nested batch requests are not supported.'
430
+ });
431
+ _context3.next = 4;
432
+ break;
433
+ case 2:
434
+ captured = createCapturedWriter();
435
+ _context3.next = 3;
436
+ return run([].concat(_toConsumableArray(request.argv), ['--json']), captured, {
437
+ invocation: invocation
438
+ });
439
+ case 3:
440
+ try {
441
+ response = JSON.parse(captured.stdout.join('\n'));
442
+ } catch (_unused) {
443
+ response = createErrorEnvelope({
444
+ command: parsed.command,
445
+ code: 'RUNTIME_ERROR',
446
+ message: 'The child command did not produce a valid JSON envelope.'
447
+ });
448
+ }
449
+ case 4:
450
+ return _context3.abrupt("return", {
451
+ request: request.argv,
452
+ status: classifyBatchResponse(response),
453
+ response: response
454
+ });
455
+ case 5:
456
+ case "end":
457
+ return _context3.stop();
458
+ }
459
+ }, _callee3);
460
+ }));
461
+ return function runBatchChild(_x3) {
462
+ return _ref0.apply(this, arguments);
463
+ };
464
+ }();
465
+
466
+ /**
467
+ * Render an already-transformed child success envelope with the same human format as its command.
468
+ */
469
+ var formatBatchChildHuman = function formatBatchChildHuman(_ref1) {
470
+ var item = _ref1.item,
471
+ invocation = _ref1.invocation;
472
+ if (!item.response.ok) {
473
+ return "Error: ".concat(item.response.error.message);
474
+ }
475
+ var parsed = parseArgs(item.request);
476
+ var definition = parsed.command ? getCommand(parsed.command) : undefined;
477
+ if (!definition) {
478
+ return formatHumanResult({
479
+ data: item.response.data
480
+ });
481
+ }
482
+
483
+ // A unified search spans every kind, so it has no single result kind and needs the grouped
484
+ // formatter instead. This is the same condition `search`'s own resolver uses to choose the
485
+ // grouped path, so the two cannot disagree.
486
+ if (definition.name === 'search' && parsed.flags.type === undefined && _typeof(item.response.data) === 'object' && item.response.data !== null) {
487
+ var _item$response$meta$c;
488
+ return formatGroupedResults({
489
+ groups: item.response.data,
490
+ totalCount: Number((_item$response$meta$c = item.response.meta.count) !== null && _item$response$meta$c !== void 0 ? _item$response$meta$c : 0),
491
+ invocation: invocation
492
+ });
493
+ }
494
+ var human = formatCommandHuman({
495
+ command: definition,
496
+ input: {
497
+ positionals: parsed.positionals,
498
+ flags: parsed.flags
499
+ },
500
+ data: item.response.data,
501
+ invocation: invocation
502
+ });
503
+ return human !== null && human !== void 0 ? human : formatHumanResult({
504
+ data: item.response.data
505
+ });
506
+ };
507
+
508
+ /**
509
+ * Execute heterogeneous registered commands concurrently in the current process and aggregate
510
+ * their existing envelopes. A valid batch exits zero even when individual child commands fail.
511
+ */
512
+ var runBatchRequests = /*#__PURE__*/function () {
513
+ var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref10) {
514
+ var command, requests, json, writer, invocation, items, succeeded, ambiguous, failed, summary, sections;
515
+ return _regeneratorRuntime.wrap(function (_context4) {
516
+ while (1) switch (_context4.prev = _context4.next) {
517
+ case 0:
518
+ command = _ref10.command, requests = _ref10.requests, json = _ref10.json, writer = _ref10.writer, invocation = _ref10.invocation;
519
+ _context4.next = 1;
520
+ return Promise.all(requests.map(function (request) {
521
+ return runBatchChild({
522
+ request: request,
523
+ invocation: invocation
524
+ });
525
+ }));
526
+ case 1:
527
+ items = _context4.sent;
528
+ succeeded = items.filter(function (item) {
529
+ return item.status === 'success';
530
+ }).length;
531
+ ambiguous = items.filter(function (item) {
532
+ return item.status === 'ambiguous';
533
+ }).length;
534
+ failed = items.length - succeeded - ambiguous;
535
+ if (!json) {
536
+ _context4.next = 2;
537
+ break;
538
+ }
539
+ writeJsonEnvelope({
540
+ envelope: createSuccessEnvelope({
541
+ envelopeType: command.envelopeType({
542
+ positionals: [],
543
+ flags: {}
544
+ }),
545
+ command: command.name,
546
+ data: items,
547
+ meta: {
548
+ succeeded: succeeded,
549
+ ambiguous: ambiguous,
550
+ failed: failed
551
+ }
552
+ }),
553
+ writer: writer
554
+ });
555
+ return _context4.abrupt("return", ExitCode.Ok);
556
+ case 2:
557
+ summary = "Batch results: ".concat(succeeded, " succeeded, ").concat(ambiguous, " ambiguous, ").concat(failed, " failed");
558
+ sections = items.map(function (item) {
559
+ return "Request: ".concat(item.request.join(' '), "\n").concat(formatBatchChildHuman({
560
+ item: item,
561
+ invocation: invocation
562
+ }));
563
+ });
564
+ writer.out([summary].concat(_toConsumableArray(sections)).join('\n\n'));
565
+ return _context4.abrupt("return", ExitCode.Ok);
566
+ case 3:
567
+ case "end":
568
+ return _context4.stop();
569
+ }
570
+ }, _callee4);
571
+ }));
572
+ return function runBatchRequests(_x4) {
573
+ return _ref11.apply(this, arguments);
574
+ };
575
+ }();
332
576
 
333
577
  /**
334
578
  * Render a grouped (multi-tool) command result, e.g. unified `search`.
@@ -336,14 +580,14 @@ var renderSingleResult = function renderSingleResult(_ref6) {
336
580
  * Each sub-result is keyed by its {@link ToolCall.key}. A sub-search that finds nothing simply
337
581
  * contributes an empty array; the command is only treated as NOT_FOUND when every group is empty.
338
582
  */
339
- var renderGroupedResult = function renderGroupedResult(_ref8) {
340
- var command = _ref8.command,
341
- input = _ref8.input,
342
- results = _ref8.results,
343
- meta = _ref8.meta,
344
- json = _ref8.json,
345
- writer = _ref8.writer,
346
- invocation = _ref8.invocation;
583
+ var renderGroupedResult = function renderGroupedResult(_ref12) {
584
+ var command = _ref12.command,
585
+ input = _ref12.input,
586
+ results = _ref12.results,
587
+ meta = _ref12.meta,
588
+ json = _ref12.json,
589
+ writer = _ref12.writer,
590
+ invocation = _ref12.invocation;
347
591
  // Assemble `{ [key]: results }`, coercing "no matches" sub-results to empty arrays so one
348
592
  // empty domain does not blank out the others. The guidelines tool returns full Markdown, so
349
593
  // summarize its highest-ranked match for search; `docs <query>` remains the detail view.
@@ -424,11 +668,11 @@ var renderGroupedResult = function renderGroupedResult(_ref8) {
424
668
  * @returns The process exit code. The bin wrapper maps this onto `process.exit`.
425
669
  */
426
670
  export var run = /*#__PURE__*/function () {
427
- var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
671
+ var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
428
672
  var argv,
429
673
  writer,
430
- _ref0,
431
- _ref0$invocation,
674
+ _ref14,
675
+ _ref14$invocation,
432
676
  invocation,
433
677
  _parseArgs,
434
678
  command,
@@ -438,33 +682,33 @@ export var run = /*#__PURE__*/function () {
438
682
  definition,
439
683
  message,
440
684
  _message2,
441
- _args3 = arguments,
685
+ _args5 = arguments,
442
686
  _t3;
443
- return _regeneratorRuntime.wrap(function (_context3) {
444
- while (1) switch (_context3.prev = _context3.next) {
687
+ return _regeneratorRuntime.wrap(function (_context5) {
688
+ while (1) switch (_context5.prev = _context5.next) {
445
689
  case 0:
446
- argv = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : process.argv.slice(2);
447
- writer = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : defaultWriter;
448
- _ref0 = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {}, _ref0$invocation = _ref0.invocation, invocation = _ref0$invocation === void 0 ? CLI_BIN_NAME : _ref0$invocation;
690
+ argv = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : process.argv.slice(2);
691
+ writer = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : defaultWriter;
692
+ _ref14 = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : {}, _ref14$invocation = _ref14.invocation, invocation = _ref14$invocation === void 0 ? CLI_BIN_NAME : _ref14$invocation;
449
693
  _parseArgs = parseArgs(argv), command = _parseArgs.command, positionals = _parseArgs.positionals, flags = _parseArgs.flags;
450
694
  json = flags.json === true; // `--version` / `-v` takes precedence and short-circuits.
451
695
  if (!(flags.version === true)) {
452
- _context3.next = 1;
696
+ _context5.next = 1;
453
697
  break;
454
698
  }
455
699
  writer.out(getVersion());
456
- return _context3.abrupt("return", ExitCode.Ok);
700
+ return _context5.abrupt("return", ExitCode.Ok);
457
701
  case 1:
458
702
  if (!(flags.help === true || command === undefined)) {
459
- _context3.next = 2;
703
+ _context5.next = 2;
460
704
  break;
461
705
  }
462
706
  writer.out(buildHelpText(invocation));
463
- return _context3.abrupt("return", command === undefined && flags.help !== true ? ExitCode.UsageError : ExitCode.Ok);
707
+ return _context5.abrupt("return", command === undefined && flags.help !== true ? ExitCode.UsageError : ExitCode.Ok);
464
708
  case 2:
465
709
  definition = getCommand(command);
466
710
  if (definition) {
467
- _context3.next = 3;
711
+ _context5.next = 3;
468
712
  break;
469
713
  }
470
714
  message = "Unknown command \"".concat(command, "\".");
@@ -484,25 +728,26 @@ export var run = /*#__PURE__*/function () {
484
728
  });
485
729
  writer.err("Run `".concat(invocation, " --help` to see available commands."));
486
730
  }
487
- return _context3.abrupt("return", ExitCode.UsageError);
731
+ return _context5.abrupt("return", ExitCode.UsageError);
488
732
  case 3:
489
- _context3.prev = 3;
490
- _context3.next = 4;
733
+ _context5.prev = 3;
734
+ _context5.next = 4;
491
735
  return runRegistryCommand({
492
736
  command: definition,
493
737
  input: {
494
738
  positionals: positionals,
495
- flags: flags
739
+ flags: flags,
740
+ rawArgs: argv
496
741
  },
497
742
  json: json,
498
743
  writer: writer,
499
744
  invocation: invocation
500
745
  });
501
746
  case 4:
502
- return _context3.abrupt("return", _context3.sent);
747
+ return _context5.abrupt("return", _context5.sent);
503
748
  case 5:
504
- _context3.prev = 5;
505
- _t3 = _context3["catch"](3);
749
+ _context5.prev = 5;
750
+ _t3 = _context5["catch"](3);
506
751
  _message2 = _t3 instanceof Error ? _t3.message : String(_t3);
507
752
  if (json) {
508
753
  writeJsonEnvelope({
@@ -519,14 +764,14 @@ export var run = /*#__PURE__*/function () {
519
764
  writer: writer
520
765
  });
521
766
  }
522
- return _context3.abrupt("return", ExitCode.RuntimeError);
767
+ return _context5.abrupt("return", ExitCode.RuntimeError);
523
768
  case 6:
524
769
  case "end":
525
- return _context3.stop();
770
+ return _context5.stop();
526
771
  }
527
- }, _callee3, null, [[3, 5]]);
772
+ }, _callee5, null, [[3, 5]]);
528
773
  }));
529
774
  return function run() {
530
- return _ref9.apply(this, arguments);
775
+ return _ref13.apply(this, arguments);
531
776
  };
532
777
  }();
@@ -2,6 +2,8 @@ import _toArray from "@babel/runtime/helpers/toArray";
2
2
  import _typeof from "@babel/runtime/helpers/typeof";
3
3
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
4
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
6
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
5
7
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
6
8
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
9
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -35,6 +37,7 @@ import { formatToken } from '../output/format-token';
35
37
  import { parseLintRuleRecords } from '../output/parse-lint-rule-records';
36
38
  import { buildManifest } from './build-manifest';
37
39
  import { getVersion } from './get-version';
40
+ import { normalizeBatchRequest } from './normalize-batch-request';
38
41
  /**
39
42
  * Shared `--limit` flag definition reused across the search-style commands.
40
43
  */
@@ -463,6 +466,76 @@ var resolveUnifiedSearch = function resolveUnifiedSearch(input) {
463
466
  };
464
467
  };
465
468
 
469
+ /**
470
+ * Split a batch invocation into argv groups introduced by repeated `--command` flags. Canonical
471
+ * tokenized groups remain unchanged; a complete request in the first token is safely normalized
472
+ * to argv without evaluating shell strings.
473
+ */
474
+ var resolveBatch = function resolveBatch(input) {
475
+ var _input$rawArgs;
476
+ var rawArgs = (_input$rawArgs = input.rawArgs) !== null && _input$rawArgs !== void 0 ? _input$rawArgs : [];
477
+ var batchIndex = rawArgs.indexOf('batch');
478
+ var tokens = rawArgs.slice(batchIndex + 1).filter(function (token) {
479
+ return token !== '--json';
480
+ });
481
+ if (tokens.length === 0) {
482
+ return {
483
+ error: 'At least one command request is required.'
484
+ };
485
+ }
486
+ if (tokens[0] !== '--command') {
487
+ return {
488
+ error: 'Each batch request must start with `--command`.'
489
+ };
490
+ }
491
+ var requests = [];
492
+ // The leading `--command` is validated above, so every remaining token either closes the open
493
+ // request or appends to it. Seeding the accumulator here keeps it non-nullable, which is what
494
+ // lets the loop stay free of "no request open yet" checks.
495
+ var current = [];
496
+ var _iterator = _createForOfIteratorHelper(tokens.slice(1)),
497
+ _step;
498
+ try {
499
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
500
+ var token = _step.value;
501
+ if (token === '--command') {
502
+ if (current.length === 0) {
503
+ return {
504
+ error: '`--command` must be followed by a non-empty command request.'
505
+ };
506
+ }
507
+ var _normalized = normalizeBatchRequest(current);
508
+ if ('error' in _normalized) {
509
+ return _normalized;
510
+ }
511
+ requests.push(_normalized);
512
+ current = [];
513
+ continue;
514
+ }
515
+ current.push(token);
516
+ }
517
+ } catch (err) {
518
+ _iterator.e(err);
519
+ } finally {
520
+ _iterator.f();
521
+ }
522
+ if (current.length === 0) {
523
+ return {
524
+ error: '`--command` must be followed by a non-empty command request.'
525
+ };
526
+ }
527
+ var normalized = normalizeBatchRequest(current);
528
+ if ('error' in normalized) {
529
+ return normalized;
530
+ }
531
+ requests.push(normalized);
532
+ return {
533
+ tools: [],
534
+ batch: requests,
535
+ meta: {}
536
+ };
537
+ };
538
+
466
539
  /**
467
540
  * The full set of CLI commands. Order here is the order shown by `manifest` and `--help`.
468
541
  */
@@ -526,6 +599,22 @@ export var commands = [{
526
599
  tool: searchKindTools[searchType]
527
600
  });
528
601
  }
602
+ }, {
603
+ name: 'batch',
604
+ description: 'Run multiple ADS CLI queries in one process. Tokenized child requests are canonical; complete-request strings are also accepted.',
605
+ usage: 'batch [--json] --command <command> [args...] [--command <command> [args...]]...',
606
+ arguments: [],
607
+ flags: [{
608
+ name: 'command',
609
+ type: 'string[]',
610
+ description: 'Canonical: a tokenized child command and its arguments. A complete quoted request is also accepted. Repeat once per child command.'
611
+ }],
612
+ examples: ['batch --command search button --type icon --command token space.200', 'batch --command "search button" --type icon --command "token space.200"', 'batch --json --command component Button --command docs spacing'],
613
+ responseTypes: ['ads-cli/batch'],
614
+ envelopeType: function envelopeType() {
615
+ return 'batch';
616
+ },
617
+ resolve: resolveBatch
529
618
  }, makeItemCommand({
530
619
  kind: 'components',
531
620
  name: 'component',