@atlaskit/ads-cli 0.1.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.
Files changed (106) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +134 -0
  3. package/bin/ads-cli.js +40 -0
  4. package/compass.yml +25 -0
  5. package/dist/cjs/cli.js +488 -0
  6. package/dist/cjs/commands/definitions.js +713 -0
  7. package/dist/cjs/commands/get-command.js +19 -0
  8. package/dist/cjs/commands/import-tool-handler.js +57 -0
  9. package/dist/cjs/commands/run-tool.js +106 -0
  10. package/dist/cjs/commands/types.js +1 -0
  11. package/dist/cjs/envelope/create-error-envelope.js +27 -0
  12. package/dist/cjs/envelope/create-success-envelope.js +38 -0
  13. package/dist/cjs/envelope/types.js +1 -0
  14. package/dist/cjs/output/disambiguation.js +31 -0
  15. package/dist/cjs/output/format-component.js +99 -0
  16. package/dist/cjs/output/format-disambiguation.js +29 -0
  17. package/dist/cjs/output/format-doc-object.js +115 -0
  18. package/dist/cjs/output/format-grouped-results.js +55 -0
  19. package/dist/cjs/output/format-icon.js +49 -0
  20. package/dist/cjs/output/format-lint-rules.js +52 -0
  21. package/dist/cjs/output/format-results.js +158 -0
  22. package/dist/cjs/output/format-token.js +39 -0
  23. package/dist/cjs/output/parse-lint-rule-records.js +47 -0
  24. package/dist/cjs/output/write-human-error.js +20 -0
  25. package/dist/cjs/output/write-human-result.js +31 -0
  26. package/dist/cjs/output/write-json-envelope.js +20 -0
  27. package/dist/cjs/output/writer.js +32 -0
  28. package/dist/cjs/parse-args.js +106 -0
  29. package/dist/cjs/types.js +53 -0
  30. package/dist/es2019/cli.js +406 -0
  31. package/dist/es2019/commands/definitions.js +683 -0
  32. package/dist/es2019/commands/get-command.js +9 -0
  33. package/dist/es2019/commands/import-tool-handler.js +22 -0
  34. package/dist/es2019/commands/run-tool.js +73 -0
  35. package/dist/es2019/commands/types.js +0 -0
  36. package/dist/es2019/envelope/create-error-envelope.js +20 -0
  37. package/dist/es2019/envelope/create-success-envelope.js +31 -0
  38. package/dist/es2019/envelope/types.js +0 -0
  39. package/dist/es2019/output/disambiguation.js +21 -0
  40. package/dist/es2019/output/format-component.js +88 -0
  41. package/dist/es2019/output/format-disambiguation.js +22 -0
  42. package/dist/es2019/output/format-doc-object.js +94 -0
  43. package/dist/es2019/output/format-grouped-results.js +51 -0
  44. package/dist/es2019/output/format-icon.js +39 -0
  45. package/dist/es2019/output/format-lint-rules.js +43 -0
  46. package/dist/es2019/output/format-results.js +142 -0
  47. package/dist/es2019/output/format-token.js +31 -0
  48. package/dist/es2019/output/parse-lint-rule-records.js +41 -0
  49. package/dist/es2019/output/write-human-error.js +14 -0
  50. package/dist/es2019/output/write-human-result.js +25 -0
  51. package/dist/es2019/output/write-json-envelope.js +15 -0
  52. package/dist/es2019/output/writer.js +22 -0
  53. package/dist/es2019/parse-args.js +100 -0
  54. package/dist/es2019/types.js +47 -0
  55. package/dist/esm/cli.js +484 -0
  56. package/dist/esm/commands/definitions.js +708 -0
  57. package/dist/esm/commands/get-command.js +13 -0
  58. package/dist/esm/commands/import-tool-handler.js +42 -0
  59. package/dist/esm/commands/run-tool.js +99 -0
  60. package/dist/esm/commands/types.js +0 -0
  61. package/dist/esm/envelope/create-error-envelope.js +21 -0
  62. package/dist/esm/envelope/create-success-envelope.js +31 -0
  63. package/dist/esm/envelope/types.js +0 -0
  64. package/dist/esm/output/disambiguation.js +24 -0
  65. package/dist/esm/output/format-component.js +92 -0
  66. package/dist/esm/output/format-disambiguation.js +22 -0
  67. package/dist/esm/output/format-doc-object.js +108 -0
  68. package/dist/esm/output/format-grouped-results.js +50 -0
  69. package/dist/esm/output/format-icon.js +42 -0
  70. package/dist/esm/output/format-lint-rules.js +46 -0
  71. package/dist/esm/output/format-results.js +151 -0
  72. package/dist/esm/output/format-token.js +32 -0
  73. package/dist/esm/output/parse-lint-rule-records.js +41 -0
  74. package/dist/esm/output/write-human-error.js +13 -0
  75. package/dist/esm/output/write-human-result.js +24 -0
  76. package/dist/esm/output/write-json-envelope.js +14 -0
  77. package/dist/esm/output/writer.js +26 -0
  78. package/dist/esm/parse-args.js +100 -0
  79. package/dist/esm/types.js +47 -0
  80. package/dist/types/cli.d.ts +20 -0
  81. package/dist/types/commands/definitions.d.ts +19 -0
  82. package/dist/types/commands/get-command.d.ts +8 -0
  83. package/dist/types/commands/import-tool-handler.d.ts +14 -0
  84. package/dist/types/commands/run-tool.d.ts +37 -0
  85. package/dist/types/commands/types.d.ts +149 -0
  86. package/dist/types/envelope/create-error-envelope.d.ts +12 -0
  87. package/dist/types/envelope/create-success-envelope.d.ts +16 -0
  88. package/dist/types/envelope/types.d.ts +60 -0
  89. package/dist/types/output/disambiguation.d.ts +50 -0
  90. package/dist/types/output/format-component.d.ts +12 -0
  91. package/dist/types/output/format-disambiguation.d.ts +11 -0
  92. package/dist/types/output/format-doc-object.d.ts +15 -0
  93. package/dist/types/output/format-grouped-results.d.ts +14 -0
  94. package/dist/types/output/format-icon.d.ts +13 -0
  95. package/dist/types/output/format-lint-rules.d.ts +14 -0
  96. package/dist/types/output/format-results.d.ts +24 -0
  97. package/dist/types/output/format-token.d.ts +12 -0
  98. package/dist/types/output/parse-lint-rule-records.d.ts +26 -0
  99. package/dist/types/output/write-human-error.d.ts +11 -0
  100. package/dist/types/output/write-human-result.d.ts +14 -0
  101. package/dist/types/output/write-json-envelope.d.ts +14 -0
  102. package/dist/types/output/writer.d.ts +25 -0
  103. package/dist/types/parse-args.d.ts +29 -0
  104. package/dist/types/types.d.ts +53 -0
  105. package/index.js +31 -0
  106. package/package.json +30 -0
@@ -0,0 +1,484 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ 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; } } }; }
4
+ 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
+ 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
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
7
+ 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; }
8
+ 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; }
9
+ /**
10
+ * The ADS CLI entrypoint.
11
+ *
12
+ * `run(argv)` parses arguments, resolves the requested command from the shared
13
+ * {@link commands} registry, dispatches to the underlying `@atlaskit/ads-mcp/tools/*`
14
+ * handler, and formats the result (human-readable by default, JSON with `--json`).
15
+ *
16
+ * It never reimplements search ranking or bundles a dataset copy — all query logic lives in
17
+ * `@atlaskit/ads-mcp`, so the MCP server, the ADS skill, and this CLI stay in lock-step.
18
+ */
19
+
20
+ import { commands } from './commands/definitions';
21
+ import { getCommand } from './commands/get-command';
22
+ import { importToolHandler } from './commands/import-tool-handler';
23
+ import { runTool } from './commands/run-tool';
24
+ import { createErrorEnvelope } from './envelope/create-error-envelope';
25
+ import { createSuccessEnvelope } from './envelope/create-success-envelope';
26
+ import { formatGroupedResults } from './output/format-grouped-results';
27
+ import { formatCompactResults } from './output/format-results';
28
+ import { writeHumanError } from './output/write-human-error';
29
+ import { writeHumanResult } from './output/write-human-result';
30
+ import { writeJsonEnvelope } from './output/write-json-envelope';
31
+ import { defaultWriter } from './output/writer';
32
+ import { parseArgs } from './parse-args';
33
+ import { ExitCode } from './types';
34
+
35
+ /**
36
+ * Resolve the CLI version from package.json. Kept in a function so a failure to read it never
37
+ * crashes the CLI (it falls back to `0.0.0`).
38
+ */
39
+ var getVersion = function getVersion() {
40
+ try {
41
+ var _pkgJson$version;
42
+ // Read our own package.json at runtime via the package-name subpath. This mirrors
43
+ // the sibling `@atlaskit/ads-mcp` package and is depth-independent, so it resolves
44
+ // correctly in both the in-repo source layout (`src/cli`) and the published build
45
+ // (`dist/cjs/cli`). Requires the `./package.json` subpath in this package's exports.
46
+ // eslint-disable-next-line import/no-extraneous-dependencies, @typescript-eslint/no-var-requires -- this uses require because not all supported node versions use the same import assertions/attributes
47
+ var pkgJson = require('@atlaskit/ads-cli/package.json');
48
+ return (_pkgJson$version = pkgJson.version) !== null && _pkgJson$version !== void 0 ? _pkgJson$version : '0.0.0';
49
+ } catch (_unused) {
50
+ return '0.0.0';
51
+ }
52
+ };
53
+
54
+ /**
55
+ * One-line description of the CLI, shown at the top of `--help`.
56
+ */
57
+ var CLI_DESCRIPTION = 'Query Atlassian Design System (ADS) structured content — components, tokens, icons, and guidelines — from the terminal.';
58
+
59
+ /**
60
+ * Build the top-level help text from the command registry so it can never drift from the
61
+ * runnable surface.
62
+ */
63
+ var buildHelpText = function buildHelpText() {
64
+ // Width of the usage "gutter"; descriptions align to this column. Usages longer than the
65
+ // gutter wrap onto their own line with the description indented beneath, so a long usage
66
+ // (e.g. `docs`, which lists every topic) never produces a single 130-column line.
67
+ var gutter = 56;
68
+ var commandLines = commands.map(function (command) {
69
+ if (command.usage.length <= gutter) {
70
+ return " ".concat(command.usage.padEnd(gutter), " ").concat(command.description);
71
+ }
72
+ // Long usage: print it on its own line(s), then the description indented beneath so the
73
+ // two stay visually associated instead of the description drifting far to the right.
74
+ var usageLines = command.usage.split(' | ').map(function (part, index) {
75
+ return index === 0 ? " ".concat(part) : " | ".concat(part);
76
+ }).join('\n');
77
+ return "".concat(usageLines, "\n ").concat(command.description);
78
+ }).join('\n');
79
+ return [CLI_DESCRIPTION, '', 'Usage', ' $ npx @atlaskit/ads-cli <command> [options]', '', 'Commands', commandLines, '', 'Global options', ' --json Emit a machine-readable JSON envelope on stdout.', ' --help, -h Show this help.', ' --version, -v Show the CLI version.', '', 'Examples', ' $ npx @atlaskit/ads-cli search button # unified: components, tokens & icons', ' $ npx @atlaskit/ads-cli search button --type component', ' $ npx @atlaskit/ads-cli component Button # detail for one component', ' $ npx @atlaskit/ads-cli token space.100 # detail for one token', ' $ npx @atlaskit/ads-cli icon --all # list every icon', ' $ npx @atlaskit/ads-cli docs spacing # foundations docs', ' $ npx @atlaskit/ads-cli docs a11y buttons # accessibility guidance', ' $ npx @atlaskit/ads-cli docs migration motion # migration guide'].join('\n');
80
+ };
81
+
82
+ /**
83
+ * Execute a registry-backed command: resolve its tool + args, dispatch, and format output.
84
+ */
85
+ var runRegistryCommand = /*#__PURE__*/function () {
86
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref) {
87
+ var _resolved$meta3;
88
+ var command, input, json, writer, resolved, _resolved$meta, results, _resolved$meta2;
89
+ return _regeneratorRuntime.wrap(function (_context2) {
90
+ while (1) switch (_context2.prev = _context2.next) {
91
+ case 0:
92
+ command = _ref.command, input = _ref.input, json = _ref.json, writer = _ref.writer;
93
+ resolved = command.resolve(input); // A resolver returning `{ error }` indicates invalid input (a usage error).
94
+ if (!('error' in resolved)) {
95
+ _context2.next = 1;
96
+ break;
97
+ }
98
+ if (json) {
99
+ writeJsonEnvelope({
100
+ envelope: createErrorEnvelope({
101
+ command: command.name,
102
+ code: 'USAGE_ERROR',
103
+ message: resolved.error
104
+ }),
105
+ writer: writer
106
+ });
107
+ } else {
108
+ writeHumanError({
109
+ message: resolved.error,
110
+ writer: writer
111
+ });
112
+ writer.err("Usage: ".concat(command.usage));
113
+ }
114
+ return _context2.abrupt("return", ExitCode.UsageError);
115
+ case 1:
116
+ if (!('data' in resolved)) {
117
+ _context2.next = 2;
118
+ break;
119
+ }
120
+ return _context2.abrupt("return", renderSingleResult({
121
+ command: command,
122
+ input: input,
123
+ result: {
124
+ data: resolved.data,
125
+ isError: false
126
+ },
127
+ meta: (_resolved$meta = resolved.meta) !== null && _resolved$meta !== void 0 ? _resolved$meta : {},
128
+ json: json,
129
+ writer: writer
130
+ }));
131
+ case 2:
132
+ _context2.next = 3;
133
+ return Promise.all(resolved.tools.map( /*#__PURE__*/function () {
134
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(tool) {
135
+ var handler, _t, _t2;
136
+ return _regeneratorRuntime.wrap(function (_context) {
137
+ while (1) switch (_context.prev = _context.next) {
138
+ case 0:
139
+ _context.next = 1;
140
+ return importToolHandler({
141
+ importPath: tool.importPath,
142
+ handlerName: tool.handlerName
143
+ });
144
+ case 1:
145
+ handler = _context.sent;
146
+ _t = _objectSpread;
147
+ _t2 = {
148
+ key: tool.key
149
+ };
150
+ _context.next = 2;
151
+ return runTool({
152
+ handler: handler,
153
+ args: tool.args
154
+ });
155
+ case 2:
156
+ return _context.abrupt("return", _t(_t2, _context.sent));
157
+ case 3:
158
+ case "end":
159
+ return _context.stop();
160
+ }
161
+ }, _callee);
162
+ }));
163
+ return function (_x2) {
164
+ return _ref3.apply(this, arguments);
165
+ };
166
+ }()));
167
+ case 3:
168
+ results = _context2.sent;
169
+ if (!resolved.grouped) {
170
+ _context2.next = 4;
171
+ break;
172
+ }
173
+ return _context2.abrupt("return", renderGroupedResult({
174
+ command: command,
175
+ input: input,
176
+ results: results,
177
+ meta: (_resolved$meta2 = resolved.meta) !== null && _resolved$meta2 !== void 0 ? _resolved$meta2 : {},
178
+ json: json,
179
+ writer: writer
180
+ }));
181
+ case 4:
182
+ return _context2.abrupt("return", renderSingleResult({
183
+ command: command,
184
+ input: input,
185
+ result: results[0],
186
+ meta: (_resolved$meta3 = resolved.meta) !== null && _resolved$meta3 !== void 0 ? _resolved$meta3 : {},
187
+ json: json,
188
+ writer: writer
189
+ }));
190
+ case 5:
191
+ case "end":
192
+ return _context2.stop();
193
+ }
194
+ }, _callee2);
195
+ }));
196
+ return function runRegistryCommand(_x) {
197
+ return _ref2.apply(this, arguments);
198
+ };
199
+ }();
200
+
201
+ /**
202
+ * Render a single-tool command result (the common case).
203
+ */
204
+ var renderSingleResult = function renderSingleResult(_ref4) {
205
+ var _command$resultKind, _ref5, _command$formatHuman;
206
+ var command = _ref4.command,
207
+ input = _ref4.input,
208
+ result = _ref4.result,
209
+ meta = _ref4.meta,
210
+ json = _ref4.json,
211
+ writer = _ref4.writer;
212
+ var isError = result.isError;
213
+
214
+ // The ADS search tools return an `Error: No … found` text block when nothing matches.
215
+ if (isError) {
216
+ var message = typeof result.data === 'string' ? result.data.replace(/^Error:\s*/, '') : 'No results found.';
217
+ if (json) {
218
+ writeJsonEnvelope({
219
+ envelope: createErrorEnvelope({
220
+ command: command.name,
221
+ code: 'NOT_FOUND',
222
+ message: message
223
+ }),
224
+ writer: writer
225
+ });
226
+ } else {
227
+ writeHumanError({
228
+ message: message,
229
+ writer: writer
230
+ });
231
+ }
232
+ return ExitCode.NotFound;
233
+ }
234
+
235
+ // Some tools signal "no match" by returning an empty (or whitespace-only) string rather than
236
+ // an `Error:` block — e.g. `docs <term>` for an unknown foundation. Treat that as NOT_FOUND so
237
+ // the user gets a clear miss instead of a silent, empty, exit-0 response.
238
+ if (typeof result.data === 'string' && result.data.trim() === '') {
239
+ var _message = "No results found".concat(input.positionals.length > 0 ? " for \"".concat(input.positionals.join(' '), "\"") : '', ".");
240
+ if (json) {
241
+ writeJsonEnvelope({
242
+ envelope: createErrorEnvelope({
243
+ command: command.name,
244
+ code: 'NOT_FOUND',
245
+ message: _message
246
+ }),
247
+ writer: writer
248
+ });
249
+ } else {
250
+ writeHumanError({
251
+ message: _message,
252
+ writer: writer
253
+ });
254
+ }
255
+ return ExitCode.NotFound;
256
+ }
257
+
258
+ // Optional post-processing (e.g. exact-match vs disambiguation for item commands). Applied
259
+ // before both JSON and human rendering so the envelope and the terminal view stay in sync.
260
+ var data = command.transform ? command.transform({
261
+ data: result.data,
262
+ input: input
263
+ }) : result.data;
264
+ if (json) {
265
+ writeJsonEnvelope({
266
+ envelope: createSuccessEnvelope({
267
+ envelopeType: command.envelopeType(input),
268
+ command: command.name,
269
+ data: data,
270
+ meta: meta
271
+ }),
272
+ writer: writer
273
+ });
274
+ return ExitCode.Ok;
275
+ }
276
+
277
+ // Default (human) output, tried in order:
278
+ // 1. Compact per-row view when the command declares a result kind (search/list).
279
+ // 2. The command's own `formatHuman` renderer for rich single-object payloads
280
+ // (component docs, a11y/migration guides, lint-rule markdown).
281
+ // 3. The generic fallback: verbatim strings (e.g. foundations markdown) or pretty JSON.
282
+ // Each step returns `null` to defer to the next, so a raw JSON dump is only ever a last resort.
283
+ var resultKind = (_command$resultKind = command.resultKind) === null || _command$resultKind === void 0 ? void 0 : _command$resultKind.call(command, input);
284
+ var compact = resultKind ? formatCompactResults({
285
+ kind: resultKind,
286
+ data: data
287
+ }) : null;
288
+ var human = (_ref5 = compact !== null && compact !== void 0 ? compact : (_command$formatHuman = command.formatHuman) === null || _command$formatHuman === void 0 ? void 0 : _command$formatHuman.call(command, data)) !== null && _ref5 !== void 0 ? _ref5 : null;
289
+ if (human !== null) {
290
+ writer.out(human);
291
+ } else {
292
+ writeHumanResult({
293
+ data: data,
294
+ writer: writer
295
+ });
296
+ }
297
+ return ExitCode.Ok;
298
+ };
299
+
300
+ /**
301
+ * Render a grouped (multi-tool) command result, e.g. unified `search`.
302
+ *
303
+ * Each sub-result is keyed by its {@link ToolCall.key}. A sub-search that finds nothing simply
304
+ * contributes an empty array; the command is only treated as NOT_FOUND when every group is empty.
305
+ */
306
+ var renderGroupedResult = function renderGroupedResult(_ref6) {
307
+ var command = _ref6.command,
308
+ input = _ref6.input,
309
+ results = _ref6.results,
310
+ meta = _ref6.meta,
311
+ json = _ref6.json,
312
+ writer = _ref6.writer;
313
+ // Assemble `{ [key]: results }`, coercing "no matches" sub-results to empty arrays so one
314
+ // empty domain does not blank out the others.
315
+ var grouped = {};
316
+ var _iterator = _createForOfIteratorHelper(results),
317
+ _step;
318
+ try {
319
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
320
+ var _step$value = _step.value,
321
+ key = _step$value.key,
322
+ data = _step$value.data,
323
+ isError = _step$value.isError;
324
+ grouped[key] = isError || !Array.isArray(data) ? [] : data;
325
+ }
326
+ } catch (err) {
327
+ _iterator.e(err);
328
+ } finally {
329
+ _iterator.f();
330
+ }
331
+ var totalCount = Object.values(grouped).reduce(function (sum, arr) {
332
+ return sum + arr.length;
333
+ }, 0);
334
+ if (totalCount === 0) {
335
+ var message = 'No components, tokens, or icons found.';
336
+ if (json) {
337
+ writeJsonEnvelope({
338
+ envelope: createErrorEnvelope({
339
+ command: command.name,
340
+ code: 'NOT_FOUND',
341
+ message: message
342
+ }),
343
+ writer: writer
344
+ });
345
+ } else {
346
+ writeHumanError({
347
+ message: message,
348
+ writer: writer
349
+ });
350
+ }
351
+ return ExitCode.NotFound;
352
+ }
353
+ if (json) {
354
+ writeJsonEnvelope({
355
+ envelope: createSuccessEnvelope({
356
+ envelopeType: command.envelopeType(input),
357
+ command: command.name,
358
+ // `data` for grouped commands is `{ components, tokens, icons }` (already counted
359
+ // per group), so `count` is the combined total across groups.
360
+ data: grouped,
361
+ meta: _objectSpread(_objectSpread({}, meta), {}, {
362
+ count: totalCount
363
+ })
364
+ }),
365
+ writer: writer
366
+ });
367
+ return ExitCode.Ok;
368
+ }
369
+ writer.out(formatGroupedResults({
370
+ groups: grouped,
371
+ totalCount: totalCount
372
+ }));
373
+ return ExitCode.Ok;
374
+ };
375
+
376
+ /**
377
+ * Parse and execute a single CLI invocation.
378
+ *
379
+ * @param argv - Arguments after `node <script>` (i.e. `process.argv.slice(2)`).
380
+ * @param writer - Injectable output sink; defaults to console-backed stdout/stderr.
381
+ * @returns The process exit code. The bin wrapper maps this onto `process.exit`.
382
+ */
383
+ export var run = /*#__PURE__*/function () {
384
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
385
+ var argv,
386
+ writer,
387
+ _parseArgs,
388
+ command,
389
+ positionals,
390
+ flags,
391
+ json,
392
+ definition,
393
+ message,
394
+ _message2,
395
+ _args3 = arguments,
396
+ _t3;
397
+ return _regeneratorRuntime.wrap(function (_context3) {
398
+ while (1) switch (_context3.prev = _context3.next) {
399
+ case 0:
400
+ argv = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : process.argv.slice(2);
401
+ writer = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : defaultWriter;
402
+ _parseArgs = parseArgs(argv), command = _parseArgs.command, positionals = _parseArgs.positionals, flags = _parseArgs.flags;
403
+ json = flags.json === true; // `--version` / `-v` takes precedence and short-circuits.
404
+ if (!(flags.version === true)) {
405
+ _context3.next = 1;
406
+ break;
407
+ }
408
+ writer.out(getVersion());
409
+ return _context3.abrupt("return", ExitCode.Ok);
410
+ case 1:
411
+ if (!(flags.help === true || command === undefined)) {
412
+ _context3.next = 2;
413
+ break;
414
+ }
415
+ writer.out(buildHelpText());
416
+ return _context3.abrupt("return", command === undefined && flags.help !== true ? ExitCode.UsageError : ExitCode.Ok);
417
+ case 2:
418
+ definition = getCommand(command);
419
+ if (definition) {
420
+ _context3.next = 3;
421
+ break;
422
+ }
423
+ message = "Unknown command \"".concat(command, "\".");
424
+ if (json) {
425
+ writeJsonEnvelope({
426
+ envelope: createErrorEnvelope({
427
+ command: command,
428
+ code: 'USAGE_ERROR',
429
+ message: message
430
+ }),
431
+ writer: writer
432
+ });
433
+ } else {
434
+ writeHumanError({
435
+ message: message,
436
+ writer: writer
437
+ });
438
+ writer.err('Run `ads-cli --help` to see available commands.');
439
+ }
440
+ return _context3.abrupt("return", ExitCode.UsageError);
441
+ case 3:
442
+ _context3.prev = 3;
443
+ _context3.next = 4;
444
+ return runRegistryCommand({
445
+ command: definition,
446
+ input: {
447
+ positionals: positionals,
448
+ flags: flags
449
+ },
450
+ json: json,
451
+ writer: writer
452
+ });
453
+ case 4:
454
+ return _context3.abrupt("return", _context3.sent);
455
+ case 5:
456
+ _context3.prev = 5;
457
+ _t3 = _context3["catch"](3);
458
+ _message2 = _t3 instanceof Error ? _t3.message : String(_t3);
459
+ if (json) {
460
+ writeJsonEnvelope({
461
+ envelope: createErrorEnvelope({
462
+ command: definition.name,
463
+ code: 'RUNTIME_ERROR',
464
+ message: _message2
465
+ }),
466
+ writer: writer
467
+ });
468
+ } else {
469
+ writeHumanError({
470
+ message: _message2,
471
+ writer: writer
472
+ });
473
+ }
474
+ return _context3.abrupt("return", ExitCode.RuntimeError);
475
+ case 6:
476
+ case "end":
477
+ return _context3.stop();
478
+ }
479
+ }, _callee3, null, [[3, 5]]);
480
+ }));
481
+ return function run() {
482
+ return _ref7.apply(this, arguments);
483
+ };
484
+ }();