@atlaskit/ads-cli 0.4.1 → 0.5.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 +16 -0
- package/README.md +3 -5
- package/bin/ads-cli.js +6 -2
- package/dist/cjs/atlas-cli.js +4 -1
- package/dist/cjs/cli.js +91 -35
- package/dist/cjs/commands/build-manifest.js +1 -2
- package/dist/cjs/commands/cli-metadata.js +2 -1
- package/dist/cjs/commands/definitions.js +16 -16
- package/dist/cjs/output/format-disambiguation.js +3 -1
- package/dist/cjs/output/format-grouped-results.js +6 -2
- package/dist/cjs/output/format-manifest.js +5 -3
- package/dist/cjs/output/format-results.js +25 -18
- package/dist/es2019/atlas-cli.js +4 -1
- package/dist/es2019/cli.js +69 -17
- package/dist/es2019/commands/build-manifest.js +1 -2
- package/dist/es2019/commands/cli-metadata.js +1 -0
- package/dist/es2019/commands/definitions.js +8 -6
- package/dist/es2019/output/format-disambiguation.js +3 -2
- package/dist/es2019/output/format-grouped-results.js +5 -2
- package/dist/es2019/output/format-manifest.js +6 -3
- package/dist/es2019/output/format-results.js +25 -18
- package/dist/esm/atlas-cli.js +4 -1
- package/dist/esm/cli.js +92 -36
- package/dist/esm/commands/build-manifest.js +1 -2
- package/dist/esm/commands/cli-metadata.js +1 -0
- package/dist/esm/commands/definitions.js +16 -16
- package/dist/esm/output/format-disambiguation.js +3 -1
- package/dist/esm/output/format-grouped-results.js +6 -2
- package/dist/esm/output/format-manifest.js +5 -3
- package/dist/esm/output/format-results.js +26 -18
- package/dist/types/cli.d.ts +10 -1
- package/dist/types/commands/build-manifest.d.ts +1 -2
- package/dist/types/commands/cli-metadata.d.ts +1 -0
- package/dist/types/commands/types.d.ts +12 -1
- package/dist/types/output/format-disambiguation.d.ts +1 -1
- package/dist/types/output/format-grouped-results.d.ts +2 -1
- package/dist/types/output/format-manifest.d.ts +2 -1
- package/dist/types/output/format-results.d.ts +4 -3
- package/index.js +1 -1
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.formatCompactResults = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _cliMetadata = require("../commands/cli-metadata");
|
|
9
10
|
/**
|
|
10
11
|
* Compact, human-readable renderers for the structured search/list results.
|
|
11
12
|
*
|
|
@@ -53,7 +54,7 @@ var truncate = function truncate(text) {
|
|
|
53
54
|
};
|
|
54
55
|
|
|
55
56
|
/**
|
|
56
|
-
* Append a `→
|
|
57
|
+
* Append a `→ <invocation> <command> <name>` drill-in hint beneath a row.
|
|
57
58
|
*
|
|
58
59
|
* Used for every `search` result, where the natural next step is to view that match in full.
|
|
59
60
|
* `--all` listings omit it because echoing every row's own name would just be noise.
|
|
@@ -62,8 +63,9 @@ var withFollowUp = function withFollowUp(_ref) {
|
|
|
62
63
|
var line = _ref.line,
|
|
63
64
|
command = _ref.command,
|
|
64
65
|
name = _ref.name,
|
|
65
|
-
showFollowUp = _ref.showFollowUp
|
|
66
|
-
|
|
66
|
+
showFollowUp = _ref.showFollowUp,
|
|
67
|
+
invocation = _ref.invocation;
|
|
68
|
+
return showFollowUp ? "".concat(line, "\n \u2192 ").concat(invocation, " ").concat(command, " ").concat(name) : line;
|
|
67
69
|
};
|
|
68
70
|
|
|
69
71
|
/**
|
|
@@ -73,7 +75,7 @@ var withFollowUp = function withFollowUp(_ref) {
|
|
|
73
75
|
* (`--all`, `--type`) or a titled section of grouped `search` — so the kind is always clear from
|
|
74
76
|
* context and a tag would just be noise.
|
|
75
77
|
*/
|
|
76
|
-
var formatComponentLine = function formatComponentLine(component, showFollowUp) {
|
|
78
|
+
var formatComponentLine = function formatComponentLine(component, showFollowUp, invocation) {
|
|
77
79
|
var _component$name;
|
|
78
80
|
var name = (_component$name = component.name) !== null && _component$name !== void 0 ? _component$name : '(unknown)';
|
|
79
81
|
var pkg = component.package ? " ".concat(component.package) : '';
|
|
@@ -84,14 +86,15 @@ var formatComponentLine = function formatComponentLine(component, showFollowUp)
|
|
|
84
86
|
line: "".concat(name).concat(pkg, " (").concat(meta, ")"),
|
|
85
87
|
command: 'component',
|
|
86
88
|
name: name,
|
|
87
|
-
showFollowUp: showFollowUp
|
|
89
|
+
showFollowUp: showFollowUp,
|
|
90
|
+
invocation: invocation
|
|
88
91
|
});
|
|
89
92
|
};
|
|
90
93
|
|
|
91
94
|
/**
|
|
92
95
|
* Render one token as a compact `name = value` line.
|
|
93
96
|
*/
|
|
94
|
-
var formatTokenLine = function formatTokenLine(tokenResult, showFollowUp) {
|
|
97
|
+
var formatTokenLine = function formatTokenLine(tokenResult, showFollowUp, invocation) {
|
|
95
98
|
var _tokenResult$name;
|
|
96
99
|
var name = (_tokenResult$name = tokenResult.name) !== null && _tokenResult$name !== void 0 ? _tokenResult$name : '(unknown)';
|
|
97
100
|
// Some token values (e.g. motion easing curves) are very long; truncate so each token stays
|
|
@@ -101,14 +104,15 @@ var formatTokenLine = function formatTokenLine(tokenResult, showFollowUp) {
|
|
|
101
104
|
line: line,
|
|
102
105
|
command: 'token',
|
|
103
106
|
name: name,
|
|
104
|
-
showFollowUp: showFollowUp
|
|
107
|
+
showFollowUp: showFollowUp,
|
|
108
|
+
invocation: invocation
|
|
105
109
|
});
|
|
106
110
|
};
|
|
107
111
|
|
|
108
112
|
/**
|
|
109
113
|
* Render one icon as a compact line with its import package and short usage note.
|
|
110
114
|
*/
|
|
111
|
-
var formatIconLine = function formatIconLine(iconResult, showFollowUp) {
|
|
115
|
+
var formatIconLine = function formatIconLine(iconResult, showFollowUp, invocation) {
|
|
112
116
|
var _iconResult$component;
|
|
113
117
|
var name = (_iconResult$component = iconResult.componentName) !== null && _iconResult$component !== void 0 ? _iconResult$component : '(unknown)';
|
|
114
118
|
var pkg = iconResult.package ? " ".concat(iconResult.package) : '';
|
|
@@ -117,31 +121,34 @@ var formatIconLine = function formatIconLine(iconResult, showFollowUp) {
|
|
|
117
121
|
line: "".concat(name).concat(pkg).concat(usage),
|
|
118
122
|
command: 'icon',
|
|
119
123
|
name: name,
|
|
120
|
-
showFollowUp: showFollowUp
|
|
124
|
+
showFollowUp: showFollowUp,
|
|
125
|
+
invocation: invocation
|
|
121
126
|
});
|
|
122
127
|
};
|
|
123
128
|
|
|
124
129
|
/**
|
|
125
130
|
* Render one foundations-document match without dumping its full Markdown body.
|
|
126
131
|
*/
|
|
127
|
-
var formatDocLine = function formatDocLine(doc, showFollowUp) {
|
|
132
|
+
var formatDocLine = function formatDocLine(doc, showFollowUp, invocation) {
|
|
128
133
|
var summary = doc.summary ? " \u2014 ".concat(doc.summary) : '';
|
|
129
134
|
var line = "".concat(doc.title).concat(summary);
|
|
130
|
-
return showFollowUp ? "".concat(line, "\n \u2192
|
|
135
|
+
return showFollowUp ? "".concat(line, "\n \u2192 ").concat(invocation, " ").concat(doc.followUp) : line;
|
|
131
136
|
};
|
|
132
137
|
|
|
133
138
|
/**
|
|
134
139
|
* Render an array of results as compact lines for the given kind. Returns `null` when the data
|
|
135
140
|
* is not an array (so the caller can fall back to generic JSON rendering).
|
|
136
141
|
*
|
|
137
|
-
* `showFollowUp` (default `false`) adds a `→
|
|
138
|
-
* row. Search enables it for both grouped and `--type` output; `--all` listings leave it off.
|
|
142
|
+
* `showFollowUp` (default `false`) adds a `→ <invocation> <command> <name>` drill-in hint beneath
|
|
143
|
+
* each row. Search enables it for both grouped and `--type` output; `--all` listings leave it off.
|
|
139
144
|
*/
|
|
140
145
|
var formatCompactResults = exports.formatCompactResults = function formatCompactResults(_ref2) {
|
|
141
146
|
var kind = _ref2.kind,
|
|
142
147
|
data = _ref2.data,
|
|
143
148
|
_ref2$showFollowUp = _ref2.showFollowUp,
|
|
144
|
-
showFollowUp = _ref2$showFollowUp === void 0 ? false : _ref2$showFollowUp
|
|
149
|
+
showFollowUp = _ref2$showFollowUp === void 0 ? false : _ref2$showFollowUp,
|
|
150
|
+
_ref2$invocation = _ref2.invocation,
|
|
151
|
+
invocation = _ref2$invocation === void 0 ? _cliMetadata.CLI_BIN_NAME : _ref2$invocation;
|
|
145
152
|
if (!Array.isArray(data)) {
|
|
146
153
|
return null;
|
|
147
154
|
}
|
|
@@ -151,13 +158,13 @@ var formatCompactResults = exports.formatCompactResults = function formatCompact
|
|
|
151
158
|
var lines = data.map(function (entry) {
|
|
152
159
|
switch (kind) {
|
|
153
160
|
case 'components':
|
|
154
|
-
return formatComponentLine(entry, showFollowUp);
|
|
161
|
+
return formatComponentLine(entry, showFollowUp, invocation);
|
|
155
162
|
case 'tokens':
|
|
156
|
-
return formatTokenLine(entry, showFollowUp);
|
|
163
|
+
return formatTokenLine(entry, showFollowUp, invocation);
|
|
157
164
|
case 'icons':
|
|
158
|
-
return formatIconLine(entry, showFollowUp);
|
|
165
|
+
return formatIconLine(entry, showFollowUp, invocation);
|
|
159
166
|
case 'docs':
|
|
160
|
-
return formatDocLine(entry, showFollowUp);
|
|
167
|
+
return formatDocLine(entry, showFollowUp, invocation);
|
|
161
168
|
default:
|
|
162
169
|
return JSON.stringify(entry);
|
|
163
170
|
}
|
package/dist/es2019/atlas-cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { run } from './cli';
|
|
3
|
+
import { CLI_ATLAS_INVOCATION } from './commands/cli-metadata';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Process entrypoint for the `atlas ads` distribution.
|
|
@@ -10,7 +11,9 @@ import { run } from './cli';
|
|
|
10
11
|
*/
|
|
11
12
|
export const main = async (argv = process.argv.slice(2)) => {
|
|
12
13
|
try {
|
|
13
|
-
const exitCode = await run(argv
|
|
14
|
+
const exitCode = await run(argv, undefined, {
|
|
15
|
+
invocation: CLI_ATLAS_INVOCATION
|
|
16
|
+
});
|
|
14
17
|
process.exitCode = exitCode;
|
|
15
18
|
} catch (error) {
|
|
16
19
|
var _error$stack;
|
package/dist/es2019/cli.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* `@atlaskit/ads-mcp`, so the MCP server, the ADS skill, and this CLI stay in lock-step.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { CLI_DESCRIPTION, globalFlags } from './commands/cli-metadata';
|
|
12
|
+
import { CLI_BIN_NAME, CLI_DESCRIPTION, globalFlags } from './commands/cli-metadata';
|
|
13
13
|
import { commands } from './commands/definitions';
|
|
14
14
|
import { getCommand } from './commands/get-command';
|
|
15
15
|
import { getVersion } from './commands/get-version';
|
|
@@ -31,7 +31,7 @@ import { ExitCode } from './types';
|
|
|
31
31
|
* Build the top-level help text from the command registry so it can never drift from the
|
|
32
32
|
* runnable surface.
|
|
33
33
|
*/
|
|
34
|
-
const buildHelpText =
|
|
34
|
+
const buildHelpText = invocation => {
|
|
35
35
|
// Width of the usage "gutter"; descriptions align to this column. Usages longer than the
|
|
36
36
|
// gutter wrap onto their own line with the description indented beneath, so a long usage
|
|
37
37
|
// (e.g. `docs`, which lists every topic) never produces a single 130-column line.
|
|
@@ -49,7 +49,46 @@ const buildHelpText = () => {
|
|
|
49
49
|
const aliases = flag.alias ? `, -${flag.alias}` : '';
|
|
50
50
|
return ` --${flag.name}${aliases}`.padEnd(18) + flag.description;
|
|
51
51
|
}).join('\n');
|
|
52
|
-
|
|
52
|
+
const examples = [{
|
|
53
|
+
command: 'search contrast',
|
|
54
|
+
comment: 'unified: components, tokens, icons & docs'
|
|
55
|
+
}, {
|
|
56
|
+
command: 'search button --type component'
|
|
57
|
+
}, {
|
|
58
|
+
command: 'search contrast --type docs'
|
|
59
|
+
}, {
|
|
60
|
+
command: 'component Button',
|
|
61
|
+
comment: 'detail for one component'
|
|
62
|
+
}, {
|
|
63
|
+
command: 'token space.100',
|
|
64
|
+
comment: 'detail for one token'
|
|
65
|
+
}, {
|
|
66
|
+
command: 'icon --all',
|
|
67
|
+
comment: 'list every icon'
|
|
68
|
+
}, {
|
|
69
|
+
command: 'docs spacing',
|
|
70
|
+
comment: 'foundations docs'
|
|
71
|
+
}, {
|
|
72
|
+
command: 'docs a11y buttons',
|
|
73
|
+
comment: 'accessibility guidance'
|
|
74
|
+
}, {
|
|
75
|
+
command: 'docs migration motion',
|
|
76
|
+
comment: 'migration guide'
|
|
77
|
+
}, {
|
|
78
|
+
command: 'manifest --json',
|
|
79
|
+
comment: 'machine-readable CLI contract'
|
|
80
|
+
}];
|
|
81
|
+
const exampleCommands = examples.map(({
|
|
82
|
+
command
|
|
83
|
+
}) => `$ ${invocation} ${command}`);
|
|
84
|
+
const exampleWidth = Math.max(...exampleCommands.map(command => command.length));
|
|
85
|
+
const exampleLines = examples.map(({
|
|
86
|
+
comment
|
|
87
|
+
}, index) => {
|
|
88
|
+
const command = exampleCommands[index];
|
|
89
|
+
return ` ${comment ? `${command.padEnd(exampleWidth)} # ${comment}` : command}`;
|
|
90
|
+
}).join('\n');
|
|
91
|
+
return [CLI_DESCRIPTION, '', 'Usage', ` $ ${invocation} <command> [options]`, '', 'Commands', commandLines, '', 'Global options', globalFlagLines, '', 'Examples', exampleLines].join('\n');
|
|
53
92
|
};
|
|
54
93
|
|
|
55
94
|
/**
|
|
@@ -59,7 +98,8 @@ const runRegistryCommand = async ({
|
|
|
59
98
|
command,
|
|
60
99
|
input,
|
|
61
100
|
json,
|
|
62
|
-
writer
|
|
101
|
+
writer,
|
|
102
|
+
invocation
|
|
63
103
|
}) => {
|
|
64
104
|
var _resolved$meta3;
|
|
65
105
|
const resolved = command.resolve(input);
|
|
@@ -99,7 +139,8 @@ const runRegistryCommand = async ({
|
|
|
99
139
|
},
|
|
100
140
|
meta: (_resolved$meta = resolved.meta) !== null && _resolved$meta !== void 0 ? _resolved$meta : {},
|
|
101
141
|
json,
|
|
102
|
-
writer
|
|
142
|
+
writer,
|
|
143
|
+
invocation
|
|
103
144
|
});
|
|
104
145
|
}
|
|
105
146
|
|
|
@@ -126,7 +167,8 @@ const runRegistryCommand = async ({
|
|
|
126
167
|
results,
|
|
127
168
|
meta: (_resolved$meta2 = resolved.meta) !== null && _resolved$meta2 !== void 0 ? _resolved$meta2 : {},
|
|
128
169
|
json,
|
|
129
|
-
writer
|
|
170
|
+
writer,
|
|
171
|
+
invocation
|
|
130
172
|
});
|
|
131
173
|
}
|
|
132
174
|
return renderSingleResult({
|
|
@@ -135,7 +177,8 @@ const runRegistryCommand = async ({
|
|
|
135
177
|
result: results[0],
|
|
136
178
|
meta: (_resolved$meta3 = resolved.meta) !== null && _resolved$meta3 !== void 0 ? _resolved$meta3 : {},
|
|
137
179
|
json,
|
|
138
|
-
writer
|
|
180
|
+
writer,
|
|
181
|
+
invocation
|
|
139
182
|
});
|
|
140
183
|
};
|
|
141
184
|
|
|
@@ -148,7 +191,8 @@ const renderSingleResult = ({
|
|
|
148
191
|
result,
|
|
149
192
|
meta,
|
|
150
193
|
json,
|
|
151
|
-
writer
|
|
194
|
+
writer,
|
|
195
|
+
invocation
|
|
152
196
|
}) => {
|
|
153
197
|
var _command$resultKind, _ref, _command$formatHuman;
|
|
154
198
|
const {
|
|
@@ -228,9 +272,12 @@ const renderSingleResult = ({
|
|
|
228
272
|
const compact = resultKind ? formatCompactResults({
|
|
229
273
|
kind: resultKind,
|
|
230
274
|
data,
|
|
231
|
-
showFollowUp: command.name === 'search'
|
|
275
|
+
showFollowUp: command.name === 'search',
|
|
276
|
+
invocation
|
|
232
277
|
}) : null;
|
|
233
|
-
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
|
|
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
|
+
invocation
|
|
280
|
+
})) !== null && _ref !== void 0 ? _ref : null;
|
|
234
281
|
if (human !== null) {
|
|
235
282
|
writer.out(human);
|
|
236
283
|
} else {
|
|
@@ -254,7 +301,8 @@ const renderGroupedResult = ({
|
|
|
254
301
|
results,
|
|
255
302
|
meta,
|
|
256
303
|
json,
|
|
257
|
-
writer
|
|
304
|
+
writer,
|
|
305
|
+
invocation
|
|
258
306
|
}) => {
|
|
259
307
|
// Assemble `{ [key]: results }`, coercing "no matches" sub-results to empty arrays so one
|
|
260
308
|
// empty domain does not blank out the others. The guidelines tool returns full Markdown, so
|
|
@@ -313,19 +361,22 @@ const renderGroupedResult = ({
|
|
|
313
361
|
}
|
|
314
362
|
writer.out(formatGroupedResults({
|
|
315
363
|
groups: grouped,
|
|
316
|
-
totalCount
|
|
364
|
+
totalCount,
|
|
365
|
+
invocation
|
|
317
366
|
}));
|
|
318
367
|
return ExitCode.Ok;
|
|
319
368
|
};
|
|
320
|
-
|
|
321
369
|
/**
|
|
322
370
|
* Parse and execute a single CLI invocation.
|
|
323
371
|
*
|
|
324
372
|
* @param argv - Arguments after `node <script>` (i.e. `process.argv.slice(2)`).
|
|
325
373
|
* @param writer - Injectable output sink; defaults to console-backed stdout/stderr.
|
|
374
|
+
* @param options - Distribution-specific rendering options.
|
|
326
375
|
* @returns The process exit code. The bin wrapper maps this onto `process.exit`.
|
|
327
376
|
*/
|
|
328
|
-
export const run = async (argv = process.argv.slice(2), writer = defaultWriter
|
|
377
|
+
export const run = async (argv = process.argv.slice(2), writer = defaultWriter, {
|
|
378
|
+
invocation = CLI_BIN_NAME
|
|
379
|
+
} = {}) => {
|
|
329
380
|
const {
|
|
330
381
|
command,
|
|
331
382
|
positionals,
|
|
@@ -342,7 +393,7 @@ export const run = async (argv = process.argv.slice(2), writer = defaultWriter)
|
|
|
342
393
|
// `--help` / `-h`, or no command at all, prints help. No command is a usage error so
|
|
343
394
|
// scripts can detect a missing invocation via the exit code.
|
|
344
395
|
if (flags.help === true || command === undefined) {
|
|
345
|
-
writer.out(buildHelpText());
|
|
396
|
+
writer.out(buildHelpText(invocation));
|
|
346
397
|
return command === undefined && flags.help !== true ? ExitCode.UsageError : ExitCode.Ok;
|
|
347
398
|
}
|
|
348
399
|
const definition = getCommand(command);
|
|
@@ -362,7 +413,7 @@ export const run = async (argv = process.argv.slice(2), writer = defaultWriter)
|
|
|
362
413
|
message,
|
|
363
414
|
writer
|
|
364
415
|
});
|
|
365
|
-
writer.err(
|
|
416
|
+
writer.err(`Run \`${invocation} --help\` to see available commands.`);
|
|
366
417
|
}
|
|
367
418
|
return ExitCode.UsageError;
|
|
368
419
|
}
|
|
@@ -374,7 +425,8 @@ export const run = async (argv = process.argv.slice(2), writer = defaultWriter)
|
|
|
374
425
|
flags
|
|
375
426
|
},
|
|
376
427
|
json,
|
|
377
|
-
writer
|
|
428
|
+
writer,
|
|
429
|
+
invocation
|
|
378
430
|
});
|
|
379
431
|
} catch (error) {
|
|
380
432
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -10,12 +10,11 @@ import { CLI_BIN_NAME, CLI_DESCRIPTION, CLI_NAME, globalFlags } from './cli-meta
|
|
|
10
10
|
* Build a serializable capability manifest from the live command registry.
|
|
11
11
|
*/
|
|
12
12
|
export const buildManifest = (commands, version) => ({
|
|
13
|
-
schemaVersion:
|
|
13
|
+
schemaVersion: 2,
|
|
14
14
|
name: CLI_NAME,
|
|
15
15
|
bin: CLI_BIN_NAME,
|
|
16
16
|
version,
|
|
17
17
|
description: CLI_DESCRIPTION,
|
|
18
|
-
invocation: `npx ${CLI_NAME}`,
|
|
19
18
|
commands: commands.map(({
|
|
20
19
|
name,
|
|
21
20
|
description,
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
export const CLI_NAME = '@atlaskit/ads-cli';
|
|
6
6
|
export const CLI_BIN_NAME = 'ads-cli';
|
|
7
|
+
export const CLI_ATLAS_INVOCATION = 'atlas ads';
|
|
7
8
|
export const CLI_DESCRIPTION = 'Query Atlassian Design System (ADS) structured content — components, tokens, icons, and guidelines — from the terminal.';
|
|
8
9
|
export const globalFlags = [{
|
|
9
10
|
name: 'json',
|
|
@@ -317,10 +317,12 @@ const makeItemCommand = ({
|
|
|
317
317
|
// disambiguation marker, both handled by `formatHuman`.
|
|
318
318
|
resultKind: input => input.flags.all ? kind : undefined,
|
|
319
319
|
envelopeType: input => input.flags.all ? listTool.envelopeType : name,
|
|
320
|
-
formatHuman: data
|
|
320
|
+
formatHuman: (data, {
|
|
321
|
+
invocation
|
|
322
|
+
}) => {
|
|
321
323
|
// Ambiguous lookup → render the "did you mean?" list; otherwise the item detail view.
|
|
322
324
|
if (isDisambiguation(data)) {
|
|
323
|
-
return formatDisambiguation(data);
|
|
325
|
+
return formatDisambiguation(data, invocation);
|
|
324
326
|
}
|
|
325
327
|
return formatHuman(data);
|
|
326
328
|
},
|
|
@@ -532,7 +534,9 @@ export const commands = [{
|
|
|
532
534
|
envelopeType: () => 'lint-rules',
|
|
533
535
|
// Ambiguous fuzzy lookup → render the "did you mean?" list; otherwise print each rule's
|
|
534
536
|
// Markdown `content` verbatim rather than JSON.
|
|
535
|
-
formatHuman:
|
|
537
|
+
formatHuman: (data, {
|
|
538
|
+
invocation
|
|
539
|
+
}) => isDisambiguation(data) ? formatDisambiguation(data, invocation) : formatLintRules(data),
|
|
536
540
|
// Mirror the item commands: a fuzzy term that matches one rule exactly (or a lone match)
|
|
537
541
|
// shows that rule's docs, but several matches with no exact name surface a disambiguation
|
|
538
542
|
// list instead of dumping every rule's full Markdown. Skipped for bare `lint-rules` (which
|
|
@@ -747,8 +751,6 @@ export const commands = [{
|
|
|
747
751
|
formatHuman: formatManifest,
|
|
748
752
|
resolve: () => ({
|
|
749
753
|
data: buildManifest(commands, getVersion()),
|
|
750
|
-
meta: {
|
|
751
|
-
schemaVersion: 1
|
|
752
|
-
}
|
|
754
|
+
meta: {}
|
|
753
755
|
})
|
|
754
756
|
}];
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Human-readable renderer for an ambiguous item lookup ("did you mean?").
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { CLI_BIN_NAME } from '../commands/cli-metadata';
|
|
5
6
|
/**
|
|
6
7
|
* Render a "did you mean?" list for an ambiguous lookup.
|
|
7
8
|
*
|
|
@@ -12,11 +13,11 @@ export const formatDisambiguation = ({
|
|
|
12
13
|
query,
|
|
13
14
|
noun,
|
|
14
15
|
candidates
|
|
15
|
-
}) => {
|
|
16
|
+
}, invocation = CLI_BIN_NAME) => {
|
|
16
17
|
const header = `Multiple ${noun}s match "${query}". Did you mean one of these?`;
|
|
17
18
|
const rows = candidates.map(candidate => {
|
|
18
19
|
const hint = candidate.hint ? ` ${candidate.hint}` : '';
|
|
19
|
-
return ` ${candidate.name}${hint}\n →
|
|
20
|
+
return ` ${candidate.name}${hint}\n → ${invocation} ${candidate.followUp}`;
|
|
20
21
|
});
|
|
21
22
|
return [header, '', ...rows].join('\n');
|
|
22
23
|
};
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* groups are skipped, so one command surfaces whatever kinds match, grouped by kind.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { CLI_BIN_NAME } from '../commands/cli-metadata';
|
|
8
9
|
import { formatCompactResults } from './format-results';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -12,7 +13,8 @@ import { formatCompactResults } from './format-results';
|
|
|
12
13
|
*/
|
|
13
14
|
export const formatGroupedResults = ({
|
|
14
15
|
groups,
|
|
15
|
-
totalCount
|
|
16
|
+
totalCount,
|
|
17
|
+
invocation = CLI_BIN_NAME
|
|
16
18
|
}) => {
|
|
17
19
|
// Fixed display order, with human-friendly section titles.
|
|
18
20
|
const sections = [{
|
|
@@ -44,7 +46,8 @@ export const formatGroupedResults = ({
|
|
|
44
46
|
const rendered = formatCompactResults({
|
|
45
47
|
kind,
|
|
46
48
|
data: entries,
|
|
47
|
-
showFollowUp: true
|
|
49
|
+
showFollowUp: true,
|
|
50
|
+
invocation
|
|
48
51
|
});
|
|
49
52
|
const body = rendered ? rendered.split('\n').slice(2).join('\n') : '';
|
|
50
53
|
blocks.push('', `${title} (${entries.length}):`, '', body);
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Format a scannable human catalog of the ADS CLI capability manifest.
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
export const formatManifest = (data, {
|
|
6
|
+
invocation
|
|
7
|
+
}) => {
|
|
8
|
+
if (typeof data !== 'object' || data === null || !('bin' in data) || typeof data.bin !== 'string' || !('version' in data) || typeof data.version !== 'string' || !('commands' in data) || !Array.isArray(data.commands)) {
|
|
6
9
|
return null;
|
|
7
10
|
}
|
|
8
11
|
const commands = data.commands.flatMap(command => {
|
|
@@ -14,5 +17,5 @@ export const formatManifest = data => {
|
|
|
14
17
|
});
|
|
15
18
|
const commandCount = commands.length;
|
|
16
19
|
const commandLabel = commandCount === 1 ? 'command' : 'commands';
|
|
17
|
-
return [`${data.bin} v${data.version} — ${commandCount} ${commandLabel}`, '', commands.join('\n'), '', `Run \`${
|
|
20
|
+
return [`${data.bin} v${data.version} — ${commandCount} ${commandLabel}`, '', commands.join('\n'), '', `Run \`${invocation} manifest --json\` for the full structured manifest.`].join('\n');
|
|
18
21
|
};
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* left to the caller's generic fallback.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import { CLI_BIN_NAME } from '../commands/cli-metadata';
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
15
|
* A component result as returned by `searchComponentsTool` / `getAllComponentsTool`.
|
|
14
16
|
* Only the fields the compact view needs are modelled; others are ignored.
|
|
@@ -38,7 +40,7 @@ const pluralize = (count, noun) => `${count} ${noun}${count === 1 ? '' : 's'}`;
|
|
|
38
40
|
const truncate = (text, max = 80) => text.length > max ? `${text.slice(0, max - 1).trimEnd()}…` : text;
|
|
39
41
|
|
|
40
42
|
/**
|
|
41
|
-
* Append a `→
|
|
43
|
+
* Append a `→ <invocation> <command> <name>` drill-in hint beneath a row.
|
|
42
44
|
*
|
|
43
45
|
* Used for every `search` result, where the natural next step is to view that match in full.
|
|
44
46
|
* `--all` listings omit it because echoing every row's own name would just be noise.
|
|
@@ -47,8 +49,9 @@ const withFollowUp = ({
|
|
|
47
49
|
line,
|
|
48
50
|
command,
|
|
49
51
|
name,
|
|
50
|
-
showFollowUp
|
|
51
|
-
|
|
52
|
+
showFollowUp,
|
|
53
|
+
invocation
|
|
54
|
+
}) => showFollowUp ? `${line}\n → ${invocation} ${command} ${name}` : line;
|
|
52
55
|
|
|
53
56
|
/**
|
|
54
57
|
* Render one component as a compact line.
|
|
@@ -57,7 +60,7 @@ const withFollowUp = ({
|
|
|
57
60
|
* (`--all`, `--type`) or a titled section of grouped `search` — so the kind is always clear from
|
|
58
61
|
* context and a tag would just be noise.
|
|
59
62
|
*/
|
|
60
|
-
const formatComponentLine = (component, showFollowUp) => {
|
|
63
|
+
const formatComponentLine = (component, showFollowUp, invocation) => {
|
|
61
64
|
var _component$name;
|
|
62
65
|
const name = (_component$name = component.name) !== null && _component$name !== void 0 ? _component$name : '(unknown)';
|
|
63
66
|
const pkg = component.package ? ` ${component.package}` : '';
|
|
@@ -68,14 +71,15 @@ const formatComponentLine = (component, showFollowUp) => {
|
|
|
68
71
|
line: `${name}${pkg} (${meta})`,
|
|
69
72
|
command: 'component',
|
|
70
73
|
name,
|
|
71
|
-
showFollowUp
|
|
74
|
+
showFollowUp,
|
|
75
|
+
invocation
|
|
72
76
|
});
|
|
73
77
|
};
|
|
74
78
|
|
|
75
79
|
/**
|
|
76
80
|
* Render one token as a compact `name = value` line.
|
|
77
81
|
*/
|
|
78
|
-
const formatTokenLine = (tokenResult, showFollowUp) => {
|
|
82
|
+
const formatTokenLine = (tokenResult, showFollowUp, invocation) => {
|
|
79
83
|
var _tokenResult$name;
|
|
80
84
|
const name = (_tokenResult$name = tokenResult.name) !== null && _tokenResult$name !== void 0 ? _tokenResult$name : '(unknown)';
|
|
81
85
|
// Some token values (e.g. motion easing curves) are very long; truncate so each token stays
|
|
@@ -85,14 +89,15 @@ const formatTokenLine = (tokenResult, showFollowUp) => {
|
|
|
85
89
|
line,
|
|
86
90
|
command: 'token',
|
|
87
91
|
name,
|
|
88
|
-
showFollowUp
|
|
92
|
+
showFollowUp,
|
|
93
|
+
invocation
|
|
89
94
|
});
|
|
90
95
|
};
|
|
91
96
|
|
|
92
97
|
/**
|
|
93
98
|
* Render one icon as a compact line with its import package and short usage note.
|
|
94
99
|
*/
|
|
95
|
-
const formatIconLine = (iconResult, showFollowUp) => {
|
|
100
|
+
const formatIconLine = (iconResult, showFollowUp, invocation) => {
|
|
96
101
|
var _iconResult$component;
|
|
97
102
|
const name = (_iconResult$component = iconResult.componentName) !== null && _iconResult$component !== void 0 ? _iconResult$component : '(unknown)';
|
|
98
103
|
const pkg = iconResult.package ? ` ${iconResult.package}` : '';
|
|
@@ -101,30 +106,32 @@ const formatIconLine = (iconResult, showFollowUp) => {
|
|
|
101
106
|
line: `${name}${pkg}${usage}`,
|
|
102
107
|
command: 'icon',
|
|
103
108
|
name,
|
|
104
|
-
showFollowUp
|
|
109
|
+
showFollowUp,
|
|
110
|
+
invocation
|
|
105
111
|
});
|
|
106
112
|
};
|
|
107
113
|
|
|
108
114
|
/**
|
|
109
115
|
* Render one foundations-document match without dumping its full Markdown body.
|
|
110
116
|
*/
|
|
111
|
-
const formatDocLine = (doc, showFollowUp) => {
|
|
117
|
+
const formatDocLine = (doc, showFollowUp, invocation) => {
|
|
112
118
|
const summary = doc.summary ? ` — ${doc.summary}` : '';
|
|
113
119
|
const line = `${doc.title}${summary}`;
|
|
114
|
-
return showFollowUp ? `${line}\n →
|
|
120
|
+
return showFollowUp ? `${line}\n → ${invocation} ${doc.followUp}` : line;
|
|
115
121
|
};
|
|
116
122
|
|
|
117
123
|
/**
|
|
118
124
|
* Render an array of results as compact lines for the given kind. Returns `null` when the data
|
|
119
125
|
* is not an array (so the caller can fall back to generic JSON rendering).
|
|
120
126
|
*
|
|
121
|
-
* `showFollowUp` (default `false`) adds a `→
|
|
122
|
-
* row. Search enables it for both grouped and `--type` output; `--all` listings leave it off.
|
|
127
|
+
* `showFollowUp` (default `false`) adds a `→ <invocation> <command> <name>` drill-in hint beneath
|
|
128
|
+
* each row. Search enables it for both grouped and `--type` output; `--all` listings leave it off.
|
|
123
129
|
*/
|
|
124
130
|
export const formatCompactResults = ({
|
|
125
131
|
kind,
|
|
126
132
|
data,
|
|
127
|
-
showFollowUp = false
|
|
133
|
+
showFollowUp = false,
|
|
134
|
+
invocation = CLI_BIN_NAME
|
|
128
135
|
}) => {
|
|
129
136
|
if (!Array.isArray(data)) {
|
|
130
137
|
return null;
|
|
@@ -135,13 +142,13 @@ export const formatCompactResults = ({
|
|
|
135
142
|
const lines = data.map(entry => {
|
|
136
143
|
switch (kind) {
|
|
137
144
|
case 'components':
|
|
138
|
-
return formatComponentLine(entry, showFollowUp);
|
|
145
|
+
return formatComponentLine(entry, showFollowUp, invocation);
|
|
139
146
|
case 'tokens':
|
|
140
|
-
return formatTokenLine(entry, showFollowUp);
|
|
147
|
+
return formatTokenLine(entry, showFollowUp, invocation);
|
|
141
148
|
case 'icons':
|
|
142
|
-
return formatIconLine(entry, showFollowUp);
|
|
149
|
+
return formatIconLine(entry, showFollowUp, invocation);
|
|
143
150
|
case 'docs':
|
|
144
|
-
return formatDocLine(entry, showFollowUp);
|
|
151
|
+
return formatDocLine(entry, showFollowUp, invocation);
|
|
145
152
|
default:
|
|
146
153
|
return JSON.stringify(entry);
|
|
147
154
|
}
|
package/dist/esm/atlas-cli.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
4
|
import { run } from './cli';
|
|
5
|
+
import { CLI_ATLAS_INVOCATION } from './commands/cli-metadata';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Process entrypoint for the `atlas ads` distribution.
|
|
@@ -23,7 +24,9 @@ export var main = /*#__PURE__*/function () {
|
|
|
23
24
|
argv = _args.length > 0 && _args[0] !== undefined ? _args[0] : process.argv.slice(2);
|
|
24
25
|
_context.prev = 1;
|
|
25
26
|
_context.next = 2;
|
|
26
|
-
return run(argv
|
|
27
|
+
return run(argv, undefined, {
|
|
28
|
+
invocation: CLI_ATLAS_INVOCATION
|
|
29
|
+
});
|
|
27
30
|
case 2:
|
|
28
31
|
exitCode = _context.sent;
|
|
29
32
|
process.exitCode = exitCode;
|