@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.
@@ -23,6 +23,8 @@ var _formatToken = require("../output/format-token");
23
23
  var _parseLintRuleRecords = require("../output/parse-lint-rule-records");
24
24
  var _buildManifest = require("./build-manifest");
25
25
  var _getVersion = require("./get-version");
26
+ 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; } } }; }
27
+ 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; } }
26
28
  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; }
27
29
  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; }
28
30
  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) { (0, _defineProperty2.default)(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; } /**
@@ -468,6 +470,72 @@ var resolveUnifiedSearch = function resolveUnifiedSearch(input) {
468
470
  };
469
471
  };
470
472
 
473
+ /**
474
+ * Split a batch invocation into argv groups introduced by repeated `--command` flags. The groups
475
+ * remain tokenized, so child commands can be routed through the existing parser without evaluating
476
+ * shell strings.
477
+ */
478
+ var resolveBatch = function resolveBatch(input) {
479
+ var _input$rawArgs;
480
+ var rawArgs = (_input$rawArgs = input.rawArgs) !== null && _input$rawArgs !== void 0 ? _input$rawArgs : [];
481
+ var batchIndex = rawArgs.indexOf('batch');
482
+ var tokens = rawArgs.slice(batchIndex + 1).filter(function (token) {
483
+ return token !== '--json';
484
+ });
485
+ if (tokens.length === 0) {
486
+ return {
487
+ error: 'At least one command request is required.'
488
+ };
489
+ }
490
+ if (tokens[0] !== '--command') {
491
+ return {
492
+ error: 'Each batch request must start with `--command`.'
493
+ };
494
+ }
495
+ var requests = [];
496
+ // The leading `--command` is validated above, so every remaining token either closes the open
497
+ // request or appends to it. Seeding the accumulator here keeps it non-nullable, which is what
498
+ // lets the loop stay free of "no request open yet" checks.
499
+ var current = [];
500
+ var _iterator = _createForOfIteratorHelper(tokens.slice(1)),
501
+ _step;
502
+ try {
503
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
504
+ var token = _step.value;
505
+ if (token === '--command') {
506
+ if (current.length === 0) {
507
+ return {
508
+ error: '`--command` must be followed by a non-empty command request.'
509
+ };
510
+ }
511
+ requests.push({
512
+ argv: current
513
+ });
514
+ current = [];
515
+ continue;
516
+ }
517
+ current.push(token);
518
+ }
519
+ } catch (err) {
520
+ _iterator.e(err);
521
+ } finally {
522
+ _iterator.f();
523
+ }
524
+ if (current.length === 0) {
525
+ return {
526
+ error: '`--command` must be followed by a non-empty command request.'
527
+ };
528
+ }
529
+ requests.push({
530
+ argv: current
531
+ });
532
+ return {
533
+ tools: [],
534
+ batch: requests,
535
+ meta: {}
536
+ };
537
+ };
538
+
471
539
  /**
472
540
  * The full set of CLI commands. Order here is the order shown by `manifest` and `--help`.
473
541
  */
@@ -531,6 +599,22 @@ var commands = exports.commands = [{
531
599
  tool: searchKindTools[searchType]
532
600
  });
533
601
  }
602
+ }, {
603
+ name: 'batch',
604
+ description: 'Run multiple ADS CLI queries, including different command types, in one process.',
605
+ usage: 'batch [--json] --command <command> [args...] [--command <command> [args...]]...',
606
+ arguments: [],
607
+ flags: [{
608
+ name: 'command',
609
+ type: 'string[]',
610
+ description: 'A child command name followed by its arguments. Repeat once per child command.'
611
+ }],
612
+ examples: ['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
534
618
  }, makeItemCommand({
535
619
  kind: 'components',
536
620
  name: 'component',
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.formatHumanResult = void 0;
8
+ var _chalk = _interopRequireDefault(require("chalk"));
9
+ /**
10
+ * Generic last-resort human formatting for a successful command result.
11
+ */
12
+
13
+ /**
14
+ * Render a successful result with the generic last-resort formatting, used when a command
15
+ * declares neither a compact result kind nor its own `formatHuman`.
16
+ *
17
+ * Structured data is pretty-printed as JSON (the underlying tools already return rich objects),
18
+ * while plain-string payloads such as guideline markdown are returned verbatim.
19
+ *
20
+ * Kept separate from the writer so callers that compose text rather than write it — notably
21
+ * `batch`, which concatenates one section per child — produce byte-identical output without
22
+ * duplicating these rules.
23
+ */
24
+ var formatHumanResult = exports.formatHumanResult = function formatHumanResult(_ref) {
25
+ var data = _ref.data;
26
+ if (typeof data === 'string') {
27
+ return data;
28
+ }
29
+ if (data === null || data === undefined) {
30
+ return _chalk.default.yellow('No results.');
31
+ }
32
+ return JSON.stringify(data, null, 2);
33
+ };
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.writeHumanResult = void 0;
8
- var _chalk = _interopRequireDefault(require("chalk"));
7
+ var _formatHumanResult = require("./format-human-result");
9
8
  /**
10
9
  * Human-readable rendering of a successful command result.
11
10
  */
@@ -13,19 +12,18 @@ var _chalk = _interopRequireDefault(require("chalk"));
13
12
  /**
14
13
  * Emit a human-readable rendering of a successful result to stdout.
15
14
  *
16
- * Structured data is pretty-printed as JSON (the underlying tools already return rich
17
- * objects), while plain-string payloads such as guideline markdown are printed verbatim.
15
+ * An absent payload is a diagnostic rather than data, so it goes to stderr to keep stdout clean
16
+ * for piping.
18
17
  */
19
18
  var writeHumanResult = exports.writeHumanResult = function writeHumanResult(_ref) {
20
19
  var data = _ref.data,
21
20
  writer = _ref.writer;
22
- if (typeof data === 'string') {
23
- writer.out(data);
24
- return;
25
- }
21
+ var text = (0, _formatHumanResult.formatHumanResult)({
22
+ data: data
23
+ });
26
24
  if (data === null || data === undefined) {
27
- writer.err(_chalk.default.yellow('No results.'));
25
+ writer.err(text);
28
26
  return;
29
27
  }
30
- writer.out(JSON.stringify(data, null, 2));
28
+ writer.out(text);
31
29
  };
@@ -18,7 +18,9 @@ import { runTool } from './commands/run-tool';
18
18
  import { createErrorEnvelope } from './envelope/create-error-envelope';
19
19
  import { createSuccessEnvelope } from './envelope/create-success-envelope';
20
20
  import { createDocSearchResults } from './output/create-doc-search-results';
21
+ import { isDisambiguation } from './output/disambiguation';
21
22
  import { formatGroupedResults } from './output/format-grouped-results';
23
+ import { formatHumanResult } from './output/format-human-result';
22
24
  import { formatCompactResults } from './output/format-results';
23
25
  import { writeHumanError } from './output/write-human-error';
24
26
  import { writeHumanResult } from './output/write-human-result';
@@ -52,6 +54,9 @@ const buildHelpText = invocation => {
52
54
  const examples = [{
53
55
  command: 'search contrast',
54
56
  comment: 'unified: components, tokens, icons & docs'
57
+ }, {
58
+ command: 'batch --command search button --type icon --command token space.200',
59
+ comment: 'independent commands in one process'
55
60
  }, {
56
61
  command: 'search button --type component'
57
62
  }, {
@@ -144,6 +149,18 @@ const runRegistryCommand = async ({
144
149
  });
145
150
  }
146
151
 
152
+ // Batch requests re-enter the same command registry in-process. Dynamic imports stay cached,
153
+ // requests run concurrently, and each child retains its normal envelope semantics.
154
+ if (resolved.batch) {
155
+ return runBatchRequests({
156
+ command,
157
+ requests: resolved.batch,
158
+ json,
159
+ writer,
160
+ invocation
161
+ });
162
+ }
163
+
147
164
  // Run every tool call the command resolved to. Single-tool commands have one; unified
148
165
  // commands (e.g. `search` with no `--type`) have several that run in parallel.
149
166
  const results = await Promise.all(resolved.tools.map(async tool => {
@@ -182,6 +199,36 @@ const runRegistryCommand = async ({
182
199
  });
183
200
  };
184
201
 
202
+ /**
203
+ * Render a command's already-transformed payload as human-readable text.
204
+ *
205
+ * Tried in order:
206
+ * 1. Compact per-row view when the command declares a result kind (search/list).
207
+ * 2. The command's own `formatHuman` renderer for rich single-object payloads
208
+ * (component docs, a11y/migration guides, lint-rule markdown).
209
+ *
210
+ * Returns `null` when neither step applies, leaving the caller to choose its own last-resort
211
+ * fallback. Shared by the single-command path and `batch` so the two cannot drift apart.
212
+ */
213
+ const formatCommandHuman = ({
214
+ command,
215
+ input,
216
+ data,
217
+ invocation
218
+ }) => {
219
+ var _command$resultKind, _ref, _command$formatHuman;
220
+ const resultKind = (_command$resultKind = command.resultKind) === null || _command$resultKind === void 0 ? void 0 : _command$resultKind.call(command, input);
221
+ const compact = resultKind ? formatCompactResults({
222
+ kind: resultKind,
223
+ data,
224
+ showFollowUp: command.name === 'search',
225
+ invocation
226
+ }) : null;
227
+ return (_ref = compact !== null && compact !== void 0 ? compact : (_command$formatHuman = command.formatHuman) === null || _command$formatHuman === void 0 ? void 0 : _command$formatHuman.call(command, data, {
228
+ invocation
229
+ })) !== null && _ref !== void 0 ? _ref : null;
230
+ };
231
+
185
232
  /**
186
233
  * Render a single-tool command result (the common case).
187
234
  */
@@ -194,7 +241,6 @@ const renderSingleResult = ({
194
241
  writer,
195
242
  invocation
196
243
  }) => {
197
- var _command$resultKind, _ref, _command$formatHuman;
198
244
  const {
199
245
  isError
200
246
  } = result;
@@ -262,22 +308,14 @@ const renderSingleResult = ({
262
308
  return ExitCode.Ok;
263
309
  }
264
310
 
265
- // Default (human) output, tried in order:
266
- // 1. Compact per-row view when the command declares a result kind (search/list).
267
- // 2. The command's own `formatHuman` renderer for rich single-object payloads
268
- // (component docs, a11y/migration guides, lint-rule markdown).
269
- // 3. The generic fallback: verbatim strings (e.g. foundations markdown) or pretty JSON.
270
- // Each step returns `null` to defer to the next, so a raw JSON dump is only ever a last resort.
271
- const resultKind = (_command$resultKind = command.resultKind) === null || _command$resultKind === void 0 ? void 0 : _command$resultKind.call(command, input);
272
- const compact = resultKind ? formatCompactResults({
273
- kind: resultKind,
311
+ // Default (human) output: the shared renderer, falling back to verbatim strings (e.g.
312
+ // foundations markdown) or pretty JSON so a raw dump is only ever a last resort.
313
+ const human = formatCommandHuman({
314
+ command,
315
+ input,
274
316
  data,
275
- showFollowUp: command.name === 'search',
276
- invocation
277
- }) : null;
278
- const human = (_ref = compact !== null && compact !== void 0 ? compact : (_command$formatHuman = command.formatHuman) === null || _command$formatHuman === void 0 ? void 0 : _command$formatHuman.call(command, data, {
279
317
  invocation
280
- })) !== null && _ref !== void 0 ? _ref : null;
318
+ });
281
319
  if (human !== null) {
282
320
  writer.out(human);
283
321
  } else {
@@ -288,6 +326,159 @@ const renderSingleResult = ({
288
326
  }
289
327
  return ExitCode.Ok;
290
328
  };
329
+ const classifyBatchResponse = response => {
330
+ if (!response.ok) {
331
+ return 'failure';
332
+ }
333
+ return isDisambiguation(response.data) ? 'ambiguous' : 'success';
334
+ };
335
+ const createCapturedWriter = () => {
336
+ const stdout = [];
337
+ const stderr = [];
338
+ return {
339
+ stdout,
340
+ stderr,
341
+ out: line => stdout.push(line),
342
+ err: line => stderr.push(line)
343
+ };
344
+ };
345
+
346
+ /**
347
+ * Execute one child argv through the normal CLI pipeline, forcing JSON so the parent can preserve
348
+ * the child's stable envelope without scraping human-readable output.
349
+ *
350
+ * There is deliberately no `--help`/`--version` guard here. Every child token is also a top-level
351
+ * token, so {@link run} already short-circuits the whole invocation to help/version text before a
352
+ * batch is ever resolved — a guard at this level would be unreachable.
353
+ */
354
+ const runBatchChild = async ({
355
+ request,
356
+ invocation
357
+ }) => {
358
+ const parsed = parseArgs(request.argv);
359
+ let response;
360
+ if (!parsed.command) {
361
+ response = createErrorEnvelope({
362
+ command: 'batch',
363
+ code: 'USAGE_ERROR',
364
+ message: 'A batch request must start with a command name.'
365
+ });
366
+ } else if (parsed.command === 'batch') {
367
+ response = createErrorEnvelope({
368
+ command: 'batch',
369
+ code: 'USAGE_ERROR',
370
+ message: 'Nested batch requests are not supported.'
371
+ });
372
+ } else {
373
+ const captured = createCapturedWriter();
374
+ await run([...request.argv, '--json'], captured, {
375
+ invocation
376
+ });
377
+ try {
378
+ response = JSON.parse(captured.stdout.join('\n'));
379
+ } catch {
380
+ response = createErrorEnvelope({
381
+ command: parsed.command,
382
+ code: 'RUNTIME_ERROR',
383
+ message: 'The child command did not produce a valid JSON envelope.'
384
+ });
385
+ }
386
+ }
387
+ return {
388
+ request: request.argv,
389
+ status: classifyBatchResponse(response),
390
+ response
391
+ };
392
+ };
393
+
394
+ /**
395
+ * Render an already-transformed child success envelope with the same human format as its command.
396
+ */
397
+ const formatBatchChildHuman = ({
398
+ item,
399
+ invocation
400
+ }) => {
401
+ if (!item.response.ok) {
402
+ return `Error: ${item.response.error.message}`;
403
+ }
404
+ const parsed = parseArgs(item.request);
405
+ const definition = parsed.command ? getCommand(parsed.command) : undefined;
406
+ if (!definition) {
407
+ return formatHumanResult({
408
+ data: item.response.data
409
+ });
410
+ }
411
+
412
+ // A unified search spans every kind, so it has no single result kind and needs the grouped
413
+ // formatter instead. This is the same condition `search`'s own resolver uses to choose the
414
+ // grouped path, so the two cannot disagree.
415
+ if (definition.name === 'search' && parsed.flags.type === undefined && typeof item.response.data === 'object' && item.response.data !== null) {
416
+ var _item$response$meta$c;
417
+ return formatGroupedResults({
418
+ groups: item.response.data,
419
+ totalCount: Number((_item$response$meta$c = item.response.meta.count) !== null && _item$response$meta$c !== void 0 ? _item$response$meta$c : 0),
420
+ invocation
421
+ });
422
+ }
423
+ const human = formatCommandHuman({
424
+ command: definition,
425
+ input: {
426
+ positionals: parsed.positionals,
427
+ flags: parsed.flags
428
+ },
429
+ data: item.response.data,
430
+ invocation
431
+ });
432
+ return human !== null && human !== void 0 ? human : formatHumanResult({
433
+ data: item.response.data
434
+ });
435
+ };
436
+
437
+ /**
438
+ * Execute heterogeneous registered commands concurrently in the current process and aggregate
439
+ * their existing envelopes. A valid batch exits zero even when individual child commands fail.
440
+ */
441
+ const runBatchRequests = async ({
442
+ command,
443
+ requests,
444
+ json,
445
+ writer,
446
+ invocation
447
+ }) => {
448
+ const items = await Promise.all(requests.map(request => runBatchChild({
449
+ request,
450
+ invocation
451
+ })));
452
+ const succeeded = items.filter(item => item.status === 'success').length;
453
+ const ambiguous = items.filter(item => item.status === 'ambiguous').length;
454
+ const failed = items.length - succeeded - ambiguous;
455
+ if (json) {
456
+ writeJsonEnvelope({
457
+ envelope: createSuccessEnvelope({
458
+ envelopeType: command.envelopeType({
459
+ positionals: [],
460
+ flags: {}
461
+ }),
462
+ command: command.name,
463
+ data: items,
464
+ meta: {
465
+ succeeded,
466
+ ambiguous,
467
+ failed
468
+ }
469
+ }),
470
+ writer
471
+ });
472
+ return ExitCode.Ok;
473
+ }
474
+ const summary = `Batch results: ${succeeded} succeeded, ${ambiguous} ambiguous, ${failed} failed`;
475
+ const sections = items.map(item => `Request: ${item.request.join(' ')}\n${formatBatchChildHuman({
476
+ item,
477
+ invocation
478
+ })}`);
479
+ writer.out([summary, ...sections].join('\n\n'));
480
+ return ExitCode.Ok;
481
+ };
291
482
 
292
483
  /**
293
484
  * Render a grouped (multi-tool) command result, e.g. unified `search`.
@@ -422,7 +613,8 @@ export const run = async (argv = process.argv.slice(2), writer = defaultWriter,
422
613
  command: definition,
423
614
  input: {
424
615
  positionals,
425
- flags
616
+ flags,
617
+ rawArgs: argv
426
618
  },
427
619
  json,
428
620
  writer,
@@ -445,6 +445,61 @@ const resolveUnifiedSearch = input => {
445
445
  };
446
446
  };
447
447
 
448
+ /**
449
+ * Split a batch invocation into argv groups introduced by repeated `--command` flags. The groups
450
+ * remain tokenized, so child commands can be routed through the existing parser without evaluating
451
+ * shell strings.
452
+ */
453
+ const resolveBatch = input => {
454
+ var _input$rawArgs;
455
+ const rawArgs = (_input$rawArgs = input.rawArgs) !== null && _input$rawArgs !== void 0 ? _input$rawArgs : [];
456
+ const batchIndex = rawArgs.indexOf('batch');
457
+ const tokens = rawArgs.slice(batchIndex + 1).filter(token => token !== '--json');
458
+ if (tokens.length === 0) {
459
+ return {
460
+ error: 'At least one command request is required.'
461
+ };
462
+ }
463
+ if (tokens[0] !== '--command') {
464
+ return {
465
+ error: 'Each batch request must start with `--command`.'
466
+ };
467
+ }
468
+ const requests = [];
469
+ // The leading `--command` is validated above, so every remaining token either closes the open
470
+ // request or appends to it. Seeding the accumulator here keeps it non-nullable, which is what
471
+ // lets the loop stay free of "no request open yet" checks.
472
+ let current = [];
473
+ for (const token of tokens.slice(1)) {
474
+ if (token === '--command') {
475
+ if (current.length === 0) {
476
+ return {
477
+ error: '`--command` must be followed by a non-empty command request.'
478
+ };
479
+ }
480
+ requests.push({
481
+ argv: current
482
+ });
483
+ current = [];
484
+ continue;
485
+ }
486
+ current.push(token);
487
+ }
488
+ if (current.length === 0) {
489
+ return {
490
+ error: '`--command` must be followed by a non-empty command request.'
491
+ };
492
+ }
493
+ requests.push({
494
+ argv: current
495
+ });
496
+ return {
497
+ tools: [],
498
+ batch: requests,
499
+ meta: {}
500
+ };
501
+ };
502
+
448
503
  /**
449
504
  * The full set of CLI commands. Order here is the order shown by `manifest` and `--help`.
450
505
  */
@@ -505,6 +560,20 @@ export const commands = [{
505
560
  tool: searchKindTools[searchType]
506
561
  });
507
562
  }
563
+ }, {
564
+ name: 'batch',
565
+ description: 'Run multiple ADS CLI queries, including different command types, in one process.',
566
+ usage: 'batch [--json] --command <command> [args...] [--command <command> [args...]]...',
567
+ arguments: [],
568
+ flags: [{
569
+ name: 'command',
570
+ type: 'string[]',
571
+ description: 'A child command name followed by its arguments. Repeat once per child command.'
572
+ }],
573
+ examples: ['batch --command search button --type icon --command token space.200', 'batch --json --command component Button --command docs spacing'],
574
+ responseTypes: ['ads-cli/batch'],
575
+ envelopeType: () => 'batch',
576
+ resolve: resolveBatch
508
577
  }, makeItemCommand({
509
578
  kind: 'components',
510
579
  name: 'component',
@@ -0,0 +1,28 @@
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 const formatHumanResult = ({
19
+ data
20
+ }) => {
21
+ if (typeof data === 'string') {
22
+ return data;
23
+ }
24
+ if (data === null || data === undefined) {
25
+ return chalk.yellow('No results.');
26
+ }
27
+ return JSON.stringify(data, null, 2);
28
+ };
@@ -2,24 +2,23 @@
2
2
  * Human-readable rendering of a successful command result.
3
3
  */
4
4
 
5
- import chalk from 'chalk';
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
- * Structured data is pretty-printed as JSON (the underlying tools already return rich
10
- * objects), while plain-string payloads such as guideline markdown are printed verbatim.
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 const writeHumanResult = ({
13
13
  data,
14
14
  writer
15
15
  }) => {
16
- if (typeof data === 'string') {
17
- writer.out(data);
18
- return;
19
- }
16
+ const text = formatHumanResult({
17
+ data
18
+ });
20
19
  if (data === null || data === undefined) {
21
- writer.err(chalk.yellow('No results.'));
20
+ writer.err(text);
22
21
  return;
23
22
  }
24
- writer.out(JSON.stringify(data, null, 2));
23
+ writer.out(text);
25
24
  };