@atlaskit/ads-cli 0.5.0 → 0.6.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/CHANGELOG.md +22 -0
- package/README.md +62 -10
- package/dist/cjs/cli.js +300 -58
- package/dist/cjs/commands/definitions.js +84 -0
- package/dist/cjs/output/format-human-result.js +33 -0
- package/dist/cjs/output/write-human-result.js +8 -10
- package/dist/es2019/cli.js +208 -16
- package/dist/es2019/commands/definitions.js +69 -0
- package/dist/es2019/output/format-human-result.js +28 -0
- package/dist/es2019/output/write-human-result.js +8 -9
- package/dist/esm/cli.js +300 -58
- package/dist/esm/commands/definitions.js +84 -0
- package/dist/esm/output/format-human-result.js +27 -0
- package/dist/esm/output/write-human-result.js +8 -9
- package/dist/types/commands/types.d.ts +16 -0
- package/dist/types/output/format-human-result.d.ts +17 -0
- package/dist/types/output/write-human-result.d.ts +2 -2
- package/dist/types/parse-args.d.ts +1 -1
- package/package.json +1 -1
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,9 @@ 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: 'independent commands in one process'
|
|
66
72
|
}, {
|
|
67
73
|
command: 'search button --type component'
|
|
68
74
|
}, {
|
|
@@ -155,7 +161,19 @@ var runRegistryCommand = /*#__PURE__*/function () {
|
|
|
155
161
|
invocation: invocation
|
|
156
162
|
}));
|
|
157
163
|
case 2:
|
|
158
|
-
|
|
164
|
+
if (!resolved.batch) {
|
|
165
|
+
_context2.next = 3;
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
return _context2.abrupt("return", runBatchRequests({
|
|
169
|
+
command: command,
|
|
170
|
+
requests: resolved.batch,
|
|
171
|
+
json: json,
|
|
172
|
+
writer: writer,
|
|
173
|
+
invocation: invocation
|
|
174
|
+
}));
|
|
175
|
+
case 3:
|
|
176
|
+
_context2.next = 4;
|
|
159
177
|
return Promise.all(resolved.tools.map( /*#__PURE__*/function () {
|
|
160
178
|
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(tool) {
|
|
161
179
|
var handler, _t, _t2;
|
|
@@ -190,10 +208,10 @@ var runRegistryCommand = /*#__PURE__*/function () {
|
|
|
190
208
|
return _ref5.apply(this, arguments);
|
|
191
209
|
};
|
|
192
210
|
}()));
|
|
193
|
-
case
|
|
211
|
+
case 4:
|
|
194
212
|
results = _context2.sent;
|
|
195
213
|
if (!resolved.grouped) {
|
|
196
|
-
_context2.next =
|
|
214
|
+
_context2.next = 5;
|
|
197
215
|
break;
|
|
198
216
|
}
|
|
199
217
|
return _context2.abrupt("return", renderGroupedResult({
|
|
@@ -205,7 +223,7 @@ var runRegistryCommand = /*#__PURE__*/function () {
|
|
|
205
223
|
writer: writer,
|
|
206
224
|
invocation: invocation
|
|
207
225
|
}));
|
|
208
|
-
case
|
|
226
|
+
case 5:
|
|
209
227
|
return _context2.abrupt("return", renderSingleResult({
|
|
210
228
|
command: command,
|
|
211
229
|
input: input,
|
|
@@ -215,7 +233,7 @@ var runRegistryCommand = /*#__PURE__*/function () {
|
|
|
215
233
|
writer: writer,
|
|
216
234
|
invocation: invocation
|
|
217
235
|
}));
|
|
218
|
-
case
|
|
236
|
+
case 6:
|
|
219
237
|
case "end":
|
|
220
238
|
return _context2.stop();
|
|
221
239
|
}
|
|
@@ -227,17 +245,45 @@ var runRegistryCommand = /*#__PURE__*/function () {
|
|
|
227
245
|
}();
|
|
228
246
|
|
|
229
247
|
/**
|
|
230
|
-
* Render a
|
|
248
|
+
* Render a command's already-transformed payload as human-readable text.
|
|
249
|
+
*
|
|
250
|
+
* Tried in order:
|
|
251
|
+
* 1. Compact per-row view when the command declares a result kind (search/list).
|
|
252
|
+
* 2. The command's own `formatHuman` renderer for rich single-object payloads
|
|
253
|
+
* (component docs, a11y/migration guides, lint-rule markdown).
|
|
254
|
+
*
|
|
255
|
+
* Returns `null` when neither step applies, leaving the caller to choose its own last-resort
|
|
256
|
+
* fallback. Shared by the single-command path and `batch` so the two cannot drift apart.
|
|
231
257
|
*/
|
|
232
|
-
var
|
|
258
|
+
var formatCommandHuman = function formatCommandHuman(_ref6) {
|
|
233
259
|
var _command$resultKind, _ref7, _command$formatHuman;
|
|
234
260
|
var command = _ref6.command,
|
|
235
261
|
input = _ref6.input,
|
|
236
|
-
|
|
237
|
-
meta = _ref6.meta,
|
|
238
|
-
json = _ref6.json,
|
|
239
|
-
writer = _ref6.writer,
|
|
262
|
+
data = _ref6.data,
|
|
240
263
|
invocation = _ref6.invocation;
|
|
264
|
+
var resultKind = (_command$resultKind = command.resultKind) === null || _command$resultKind === void 0 ? void 0 : _command$resultKind.call(command, input);
|
|
265
|
+
var compact = resultKind ? formatCompactResults({
|
|
266
|
+
kind: resultKind,
|
|
267
|
+
data: data,
|
|
268
|
+
showFollowUp: command.name === 'search',
|
|
269
|
+
invocation: invocation
|
|
270
|
+
}) : null;
|
|
271
|
+
return (_ref7 = compact !== null && compact !== void 0 ? compact : (_command$formatHuman = command.formatHuman) === null || _command$formatHuman === void 0 ? void 0 : _command$formatHuman.call(command, data, {
|
|
272
|
+
invocation: invocation
|
|
273
|
+
})) !== null && _ref7 !== void 0 ? _ref7 : null;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Render a single-tool command result (the common case).
|
|
278
|
+
*/
|
|
279
|
+
var renderSingleResult = function renderSingleResult(_ref8) {
|
|
280
|
+
var command = _ref8.command,
|
|
281
|
+
input = _ref8.input,
|
|
282
|
+
result = _ref8.result,
|
|
283
|
+
meta = _ref8.meta,
|
|
284
|
+
json = _ref8.json,
|
|
285
|
+
writer = _ref8.writer,
|
|
286
|
+
invocation = _ref8.invocation;
|
|
241
287
|
var isError = result.isError;
|
|
242
288
|
|
|
243
289
|
// The ADS search tools return an `Error: No … found` text block when nothing matches.
|
|
@@ -303,22 +349,14 @@ var renderSingleResult = function renderSingleResult(_ref6) {
|
|
|
303
349
|
return ExitCode.Ok;
|
|
304
350
|
}
|
|
305
351
|
|
|
306
|
-
// Default (human) output,
|
|
307
|
-
//
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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,
|
|
352
|
+
// Default (human) output: the shared renderer, falling back to verbatim strings (e.g.
|
|
353
|
+
// foundations markdown) or pretty JSON so a raw dump is only ever a last resort.
|
|
354
|
+
var human = formatCommandHuman({
|
|
355
|
+
command: command,
|
|
356
|
+
input: input,
|
|
315
357
|
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
358
|
invocation: invocation
|
|
321
|
-
})
|
|
359
|
+
});
|
|
322
360
|
if (human !== null) {
|
|
323
361
|
writer.out(human);
|
|
324
362
|
} else {
|
|
@@ -329,6 +367,209 @@ var renderSingleResult = function renderSingleResult(_ref6) {
|
|
|
329
367
|
}
|
|
330
368
|
return ExitCode.Ok;
|
|
331
369
|
};
|
|
370
|
+
var classifyBatchResponse = function classifyBatchResponse(response) {
|
|
371
|
+
if (!response.ok) {
|
|
372
|
+
return 'failure';
|
|
373
|
+
}
|
|
374
|
+
return isDisambiguation(response.data) ? 'ambiguous' : 'success';
|
|
375
|
+
};
|
|
376
|
+
var createCapturedWriter = function createCapturedWriter() {
|
|
377
|
+
var stdout = [];
|
|
378
|
+
var stderr = [];
|
|
379
|
+
return {
|
|
380
|
+
stdout: stdout,
|
|
381
|
+
stderr: stderr,
|
|
382
|
+
out: function out(line) {
|
|
383
|
+
return stdout.push(line);
|
|
384
|
+
},
|
|
385
|
+
err: function err(line) {
|
|
386
|
+
return stderr.push(line);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Execute one child argv through the normal CLI pipeline, forcing JSON so the parent can preserve
|
|
393
|
+
* the child's stable envelope without scraping human-readable output.
|
|
394
|
+
*
|
|
395
|
+
* There is deliberately no `--help`/`--version` guard here. Every child token is also a top-level
|
|
396
|
+
* token, so {@link run} already short-circuits the whole invocation to help/version text before a
|
|
397
|
+
* batch is ever resolved — a guard at this level would be unreachable.
|
|
398
|
+
*/
|
|
399
|
+
var runBatchChild = /*#__PURE__*/function () {
|
|
400
|
+
var _ref0 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref9) {
|
|
401
|
+
var request, invocation, parsed, response, captured;
|
|
402
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
403
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
404
|
+
case 0:
|
|
405
|
+
request = _ref9.request, invocation = _ref9.invocation;
|
|
406
|
+
parsed = parseArgs(request.argv);
|
|
407
|
+
if (parsed.command) {
|
|
408
|
+
_context3.next = 1;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
response = createErrorEnvelope({
|
|
412
|
+
command: 'batch',
|
|
413
|
+
code: 'USAGE_ERROR',
|
|
414
|
+
message: 'A batch request must start with a command name.'
|
|
415
|
+
});
|
|
416
|
+
_context3.next = 4;
|
|
417
|
+
break;
|
|
418
|
+
case 1:
|
|
419
|
+
if (!(parsed.command === 'batch')) {
|
|
420
|
+
_context3.next = 2;
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
response = createErrorEnvelope({
|
|
424
|
+
command: 'batch',
|
|
425
|
+
code: 'USAGE_ERROR',
|
|
426
|
+
message: 'Nested batch requests are not supported.'
|
|
427
|
+
});
|
|
428
|
+
_context3.next = 4;
|
|
429
|
+
break;
|
|
430
|
+
case 2:
|
|
431
|
+
captured = createCapturedWriter();
|
|
432
|
+
_context3.next = 3;
|
|
433
|
+
return run([].concat(_toConsumableArray(request.argv), ['--json']), captured, {
|
|
434
|
+
invocation: invocation
|
|
435
|
+
});
|
|
436
|
+
case 3:
|
|
437
|
+
try {
|
|
438
|
+
response = JSON.parse(captured.stdout.join('\n'));
|
|
439
|
+
} catch (_unused) {
|
|
440
|
+
response = createErrorEnvelope({
|
|
441
|
+
command: parsed.command,
|
|
442
|
+
code: 'RUNTIME_ERROR',
|
|
443
|
+
message: 'The child command did not produce a valid JSON envelope.'
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
case 4:
|
|
447
|
+
return _context3.abrupt("return", {
|
|
448
|
+
request: request.argv,
|
|
449
|
+
status: classifyBatchResponse(response),
|
|
450
|
+
response: response
|
|
451
|
+
});
|
|
452
|
+
case 5:
|
|
453
|
+
case "end":
|
|
454
|
+
return _context3.stop();
|
|
455
|
+
}
|
|
456
|
+
}, _callee3);
|
|
457
|
+
}));
|
|
458
|
+
return function runBatchChild(_x3) {
|
|
459
|
+
return _ref0.apply(this, arguments);
|
|
460
|
+
};
|
|
461
|
+
}();
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Render an already-transformed child success envelope with the same human format as its command.
|
|
465
|
+
*/
|
|
466
|
+
var formatBatchChildHuman = function formatBatchChildHuman(_ref1) {
|
|
467
|
+
var item = _ref1.item,
|
|
468
|
+
invocation = _ref1.invocation;
|
|
469
|
+
if (!item.response.ok) {
|
|
470
|
+
return "Error: ".concat(item.response.error.message);
|
|
471
|
+
}
|
|
472
|
+
var parsed = parseArgs(item.request);
|
|
473
|
+
var definition = parsed.command ? getCommand(parsed.command) : undefined;
|
|
474
|
+
if (!definition) {
|
|
475
|
+
return formatHumanResult({
|
|
476
|
+
data: item.response.data
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// A unified search spans every kind, so it has no single result kind and needs the grouped
|
|
481
|
+
// formatter instead. This is the same condition `search`'s own resolver uses to choose the
|
|
482
|
+
// grouped path, so the two cannot disagree.
|
|
483
|
+
if (definition.name === 'search' && parsed.flags.type === undefined && _typeof(item.response.data) === 'object' && item.response.data !== null) {
|
|
484
|
+
var _item$response$meta$c;
|
|
485
|
+
return formatGroupedResults({
|
|
486
|
+
groups: item.response.data,
|
|
487
|
+
totalCount: Number((_item$response$meta$c = item.response.meta.count) !== null && _item$response$meta$c !== void 0 ? _item$response$meta$c : 0),
|
|
488
|
+
invocation: invocation
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
var human = formatCommandHuman({
|
|
492
|
+
command: definition,
|
|
493
|
+
input: {
|
|
494
|
+
positionals: parsed.positionals,
|
|
495
|
+
flags: parsed.flags
|
|
496
|
+
},
|
|
497
|
+
data: item.response.data,
|
|
498
|
+
invocation: invocation
|
|
499
|
+
});
|
|
500
|
+
return human !== null && human !== void 0 ? human : formatHumanResult({
|
|
501
|
+
data: item.response.data
|
|
502
|
+
});
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Execute heterogeneous registered commands concurrently in the current process and aggregate
|
|
507
|
+
* their existing envelopes. A valid batch exits zero even when individual child commands fail.
|
|
508
|
+
*/
|
|
509
|
+
var runBatchRequests = /*#__PURE__*/function () {
|
|
510
|
+
var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref10) {
|
|
511
|
+
var command, requests, json, writer, invocation, items, succeeded, ambiguous, failed, summary, sections;
|
|
512
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
513
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
514
|
+
case 0:
|
|
515
|
+
command = _ref10.command, requests = _ref10.requests, json = _ref10.json, writer = _ref10.writer, invocation = _ref10.invocation;
|
|
516
|
+
_context4.next = 1;
|
|
517
|
+
return Promise.all(requests.map(function (request) {
|
|
518
|
+
return runBatchChild({
|
|
519
|
+
request: request,
|
|
520
|
+
invocation: invocation
|
|
521
|
+
});
|
|
522
|
+
}));
|
|
523
|
+
case 1:
|
|
524
|
+
items = _context4.sent;
|
|
525
|
+
succeeded = items.filter(function (item) {
|
|
526
|
+
return item.status === 'success';
|
|
527
|
+
}).length;
|
|
528
|
+
ambiguous = items.filter(function (item) {
|
|
529
|
+
return item.status === 'ambiguous';
|
|
530
|
+
}).length;
|
|
531
|
+
failed = items.length - succeeded - ambiguous;
|
|
532
|
+
if (!json) {
|
|
533
|
+
_context4.next = 2;
|
|
534
|
+
break;
|
|
535
|
+
}
|
|
536
|
+
writeJsonEnvelope({
|
|
537
|
+
envelope: createSuccessEnvelope({
|
|
538
|
+
envelopeType: command.envelopeType({
|
|
539
|
+
positionals: [],
|
|
540
|
+
flags: {}
|
|
541
|
+
}),
|
|
542
|
+
command: command.name,
|
|
543
|
+
data: items,
|
|
544
|
+
meta: {
|
|
545
|
+
succeeded: succeeded,
|
|
546
|
+
ambiguous: ambiguous,
|
|
547
|
+
failed: failed
|
|
548
|
+
}
|
|
549
|
+
}),
|
|
550
|
+
writer: writer
|
|
551
|
+
});
|
|
552
|
+
return _context4.abrupt("return", ExitCode.Ok);
|
|
553
|
+
case 2:
|
|
554
|
+
summary = "Batch results: ".concat(succeeded, " succeeded, ").concat(ambiguous, " ambiguous, ").concat(failed, " failed");
|
|
555
|
+
sections = items.map(function (item) {
|
|
556
|
+
return "Request: ".concat(item.request.join(' '), "\n").concat(formatBatchChildHuman({
|
|
557
|
+
item: item,
|
|
558
|
+
invocation: invocation
|
|
559
|
+
}));
|
|
560
|
+
});
|
|
561
|
+
writer.out([summary].concat(_toConsumableArray(sections)).join('\n\n'));
|
|
562
|
+
return _context4.abrupt("return", ExitCode.Ok);
|
|
563
|
+
case 3:
|
|
564
|
+
case "end":
|
|
565
|
+
return _context4.stop();
|
|
566
|
+
}
|
|
567
|
+
}, _callee4);
|
|
568
|
+
}));
|
|
569
|
+
return function runBatchRequests(_x4) {
|
|
570
|
+
return _ref11.apply(this, arguments);
|
|
571
|
+
};
|
|
572
|
+
}();
|
|
332
573
|
|
|
333
574
|
/**
|
|
334
575
|
* Render a grouped (multi-tool) command result, e.g. unified `search`.
|
|
@@ -336,14 +577,14 @@ var renderSingleResult = function renderSingleResult(_ref6) {
|
|
|
336
577
|
* Each sub-result is keyed by its {@link ToolCall.key}. A sub-search that finds nothing simply
|
|
337
578
|
* contributes an empty array; the command is only treated as NOT_FOUND when every group is empty.
|
|
338
579
|
*/
|
|
339
|
-
var renderGroupedResult = function renderGroupedResult(
|
|
340
|
-
var command =
|
|
341
|
-
input =
|
|
342
|
-
results =
|
|
343
|
-
meta =
|
|
344
|
-
json =
|
|
345
|
-
writer =
|
|
346
|
-
invocation =
|
|
580
|
+
var renderGroupedResult = function renderGroupedResult(_ref12) {
|
|
581
|
+
var command = _ref12.command,
|
|
582
|
+
input = _ref12.input,
|
|
583
|
+
results = _ref12.results,
|
|
584
|
+
meta = _ref12.meta,
|
|
585
|
+
json = _ref12.json,
|
|
586
|
+
writer = _ref12.writer,
|
|
587
|
+
invocation = _ref12.invocation;
|
|
347
588
|
// Assemble `{ [key]: results }`, coercing "no matches" sub-results to empty arrays so one
|
|
348
589
|
// empty domain does not blank out the others. The guidelines tool returns full Markdown, so
|
|
349
590
|
// summarize its highest-ranked match for search; `docs <query>` remains the detail view.
|
|
@@ -424,11 +665,11 @@ var renderGroupedResult = function renderGroupedResult(_ref8) {
|
|
|
424
665
|
* @returns The process exit code. The bin wrapper maps this onto `process.exit`.
|
|
425
666
|
*/
|
|
426
667
|
export var run = /*#__PURE__*/function () {
|
|
427
|
-
var
|
|
668
|
+
var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
428
669
|
var argv,
|
|
429
670
|
writer,
|
|
430
|
-
|
|
431
|
-
|
|
671
|
+
_ref14,
|
|
672
|
+
_ref14$invocation,
|
|
432
673
|
invocation,
|
|
433
674
|
_parseArgs,
|
|
434
675
|
command,
|
|
@@ -438,33 +679,33 @@ export var run = /*#__PURE__*/function () {
|
|
|
438
679
|
definition,
|
|
439
680
|
message,
|
|
440
681
|
_message2,
|
|
441
|
-
|
|
682
|
+
_args5 = arguments,
|
|
442
683
|
_t3;
|
|
443
|
-
return _regeneratorRuntime.wrap(function (
|
|
444
|
-
while (1) switch (
|
|
684
|
+
return _regeneratorRuntime.wrap(function (_context5) {
|
|
685
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
445
686
|
case 0:
|
|
446
|
-
argv =
|
|
447
|
-
writer =
|
|
448
|
-
|
|
687
|
+
argv = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : process.argv.slice(2);
|
|
688
|
+
writer = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : defaultWriter;
|
|
689
|
+
_ref14 = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : {}, _ref14$invocation = _ref14.invocation, invocation = _ref14$invocation === void 0 ? CLI_BIN_NAME : _ref14$invocation;
|
|
449
690
|
_parseArgs = parseArgs(argv), command = _parseArgs.command, positionals = _parseArgs.positionals, flags = _parseArgs.flags;
|
|
450
691
|
json = flags.json === true; // `--version` / `-v` takes precedence and short-circuits.
|
|
451
692
|
if (!(flags.version === true)) {
|
|
452
|
-
|
|
693
|
+
_context5.next = 1;
|
|
453
694
|
break;
|
|
454
695
|
}
|
|
455
696
|
writer.out(getVersion());
|
|
456
|
-
return
|
|
697
|
+
return _context5.abrupt("return", ExitCode.Ok);
|
|
457
698
|
case 1:
|
|
458
699
|
if (!(flags.help === true || command === undefined)) {
|
|
459
|
-
|
|
700
|
+
_context5.next = 2;
|
|
460
701
|
break;
|
|
461
702
|
}
|
|
462
703
|
writer.out(buildHelpText(invocation));
|
|
463
|
-
return
|
|
704
|
+
return _context5.abrupt("return", command === undefined && flags.help !== true ? ExitCode.UsageError : ExitCode.Ok);
|
|
464
705
|
case 2:
|
|
465
706
|
definition = getCommand(command);
|
|
466
707
|
if (definition) {
|
|
467
|
-
|
|
708
|
+
_context5.next = 3;
|
|
468
709
|
break;
|
|
469
710
|
}
|
|
470
711
|
message = "Unknown command \"".concat(command, "\".");
|
|
@@ -484,25 +725,26 @@ export var run = /*#__PURE__*/function () {
|
|
|
484
725
|
});
|
|
485
726
|
writer.err("Run `".concat(invocation, " --help` to see available commands."));
|
|
486
727
|
}
|
|
487
|
-
return
|
|
728
|
+
return _context5.abrupt("return", ExitCode.UsageError);
|
|
488
729
|
case 3:
|
|
489
|
-
|
|
490
|
-
|
|
730
|
+
_context5.prev = 3;
|
|
731
|
+
_context5.next = 4;
|
|
491
732
|
return runRegistryCommand({
|
|
492
733
|
command: definition,
|
|
493
734
|
input: {
|
|
494
735
|
positionals: positionals,
|
|
495
|
-
flags: flags
|
|
736
|
+
flags: flags,
|
|
737
|
+
rawArgs: argv
|
|
496
738
|
},
|
|
497
739
|
json: json,
|
|
498
740
|
writer: writer,
|
|
499
741
|
invocation: invocation
|
|
500
742
|
});
|
|
501
743
|
case 4:
|
|
502
|
-
return
|
|
744
|
+
return _context5.abrupt("return", _context5.sent);
|
|
503
745
|
case 5:
|
|
504
|
-
|
|
505
|
-
_t3 =
|
|
746
|
+
_context5.prev = 5;
|
|
747
|
+
_t3 = _context5["catch"](3);
|
|
506
748
|
_message2 = _t3 instanceof Error ? _t3.message : String(_t3);
|
|
507
749
|
if (json) {
|
|
508
750
|
writeJsonEnvelope({
|
|
@@ -519,14 +761,14 @@ export var run = /*#__PURE__*/function () {
|
|
|
519
761
|
writer: writer
|
|
520
762
|
});
|
|
521
763
|
}
|
|
522
|
-
return
|
|
764
|
+
return _context5.abrupt("return", ExitCode.RuntimeError);
|
|
523
765
|
case 6:
|
|
524
766
|
case "end":
|
|
525
|
-
return
|
|
767
|
+
return _context5.stop();
|
|
526
768
|
}
|
|
527
|
-
},
|
|
769
|
+
}, _callee5, null, [[3, 5]]);
|
|
528
770
|
}));
|
|
529
771
|
return function run() {
|
|
530
|
-
return
|
|
772
|
+
return _ref13.apply(this, arguments);
|
|
531
773
|
};
|
|
532
774
|
}();
|
|
@@ -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; }
|
|
@@ -463,6 +465,72 @@ var resolveUnifiedSearch = function resolveUnifiedSearch(input) {
|
|
|
463
465
|
};
|
|
464
466
|
};
|
|
465
467
|
|
|
468
|
+
/**
|
|
469
|
+
* Split a batch invocation into argv groups introduced by repeated `--command` flags. The groups
|
|
470
|
+
* remain tokenized, so child commands can be routed through the existing parser without evaluating
|
|
471
|
+
* shell strings.
|
|
472
|
+
*/
|
|
473
|
+
var resolveBatch = function resolveBatch(input) {
|
|
474
|
+
var _input$rawArgs;
|
|
475
|
+
var rawArgs = (_input$rawArgs = input.rawArgs) !== null && _input$rawArgs !== void 0 ? _input$rawArgs : [];
|
|
476
|
+
var batchIndex = rawArgs.indexOf('batch');
|
|
477
|
+
var tokens = rawArgs.slice(batchIndex + 1).filter(function (token) {
|
|
478
|
+
return token !== '--json';
|
|
479
|
+
});
|
|
480
|
+
if (tokens.length === 0) {
|
|
481
|
+
return {
|
|
482
|
+
error: 'At least one command request is required.'
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
if (tokens[0] !== '--command') {
|
|
486
|
+
return {
|
|
487
|
+
error: 'Each batch request must start with `--command`.'
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
var requests = [];
|
|
491
|
+
// The leading `--command` is validated above, so every remaining token either closes the open
|
|
492
|
+
// request or appends to it. Seeding the accumulator here keeps it non-nullable, which is what
|
|
493
|
+
// lets the loop stay free of "no request open yet" checks.
|
|
494
|
+
var current = [];
|
|
495
|
+
var _iterator = _createForOfIteratorHelper(tokens.slice(1)),
|
|
496
|
+
_step;
|
|
497
|
+
try {
|
|
498
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
499
|
+
var token = _step.value;
|
|
500
|
+
if (token === '--command') {
|
|
501
|
+
if (current.length === 0) {
|
|
502
|
+
return {
|
|
503
|
+
error: '`--command` must be followed by a non-empty command request.'
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
requests.push({
|
|
507
|
+
argv: current
|
|
508
|
+
});
|
|
509
|
+
current = [];
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
current.push(token);
|
|
513
|
+
}
|
|
514
|
+
} catch (err) {
|
|
515
|
+
_iterator.e(err);
|
|
516
|
+
} finally {
|
|
517
|
+
_iterator.f();
|
|
518
|
+
}
|
|
519
|
+
if (current.length === 0) {
|
|
520
|
+
return {
|
|
521
|
+
error: '`--command` must be followed by a non-empty command request.'
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
requests.push({
|
|
525
|
+
argv: current
|
|
526
|
+
});
|
|
527
|
+
return {
|
|
528
|
+
tools: [],
|
|
529
|
+
batch: requests,
|
|
530
|
+
meta: {}
|
|
531
|
+
};
|
|
532
|
+
};
|
|
533
|
+
|
|
466
534
|
/**
|
|
467
535
|
* The full set of CLI commands. Order here is the order shown by `manifest` and `--help`.
|
|
468
536
|
*/
|
|
@@ -526,6 +594,22 @@ export var commands = [{
|
|
|
526
594
|
tool: searchKindTools[searchType]
|
|
527
595
|
});
|
|
528
596
|
}
|
|
597
|
+
}, {
|
|
598
|
+
name: 'batch',
|
|
599
|
+
description: 'Run multiple ADS CLI queries, including different command types, in one process.',
|
|
600
|
+
usage: 'batch [--json] --command <command> [args...] [--command <command> [args...]]...',
|
|
601
|
+
arguments: [],
|
|
602
|
+
flags: [{
|
|
603
|
+
name: 'command',
|
|
604
|
+
type: 'string[]',
|
|
605
|
+
description: 'A child command name followed by its arguments. Repeat once per child command.'
|
|
606
|
+
}],
|
|
607
|
+
examples: ['batch --command search button --type icon --command token space.200', 'batch --json --command component Button --command docs spacing'],
|
|
608
|
+
responseTypes: ['ads-cli/batch'],
|
|
609
|
+
envelopeType: function envelopeType() {
|
|
610
|
+
return 'batch';
|
|
611
|
+
},
|
|
612
|
+
resolve: resolveBatch
|
|
529
613
|
}, makeItemCommand({
|
|
530
614
|
kind: 'components',
|
|
531
615
|
name: 'component',
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic last-resort human formatting for a successful command result.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Render a successful result with the generic last-resort formatting, used when a command
|
|
9
|
+
* declares neither a compact result kind nor its own `formatHuman`.
|
|
10
|
+
*
|
|
11
|
+
* Structured data is pretty-printed as JSON (the underlying tools already return rich objects),
|
|
12
|
+
* while plain-string payloads such as guideline markdown are returned verbatim.
|
|
13
|
+
*
|
|
14
|
+
* Kept separate from the writer so callers that compose text rather than write it — notably
|
|
15
|
+
* `batch`, which concatenates one section per child — produce byte-identical output without
|
|
16
|
+
* duplicating these rules.
|
|
17
|
+
*/
|
|
18
|
+
export var formatHumanResult = function formatHumanResult(_ref) {
|
|
19
|
+
var data = _ref.data;
|
|
20
|
+
if (typeof data === 'string') {
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
if (data === null || data === undefined) {
|
|
24
|
+
return chalk.yellow('No results.');
|
|
25
|
+
}
|
|
26
|
+
return JSON.stringify(data, null, 2);
|
|
27
|
+
};
|
|
@@ -2,23 +2,22 @@
|
|
|
2
2
|
* Human-readable rendering of a successful command result.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import { formatHumanResult } from './format-human-result';
|
|
6
6
|
/**
|
|
7
7
|
* Emit a human-readable rendering of a successful result to stdout.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* An absent payload is a diagnostic rather than data, so it goes to stderr to keep stdout clean
|
|
10
|
+
* for piping.
|
|
11
11
|
*/
|
|
12
12
|
export var writeHumanResult = function writeHumanResult(_ref) {
|
|
13
13
|
var data = _ref.data,
|
|
14
14
|
writer = _ref.writer;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
15
|
+
var text = formatHumanResult({
|
|
16
|
+
data: data
|
|
17
|
+
});
|
|
19
18
|
if (data === null || data === undefined) {
|
|
20
|
-
writer.err(
|
|
19
|
+
writer.err(text);
|
|
21
20
|
return;
|
|
22
21
|
}
|
|
23
|
-
writer.out(
|
|
22
|
+
writer.out(text);
|
|
24
23
|
};
|