@paradigma-inc/flywheel 0.1.74 → 0.1.78
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/README.md +29 -0
- package/package.json +1 -1
- package/skills/flywheel/references/flywheel-mcp-tool-map.md +2 -1
- package/src/cli.mjs +55 -0
- package/src/completion.mjs +326 -0
- package/src/public-command-metadata.mjs +240 -0
- package/src/runtime/delegate.mjs +2 -2
- package/src/runtime/vendor/flywheel-cli-dist/commands/help-metadata.d.ts +32 -0
- package/src/runtime/vendor/flywheel-cli-dist/commands/help-metadata.js +112 -0
- package/src/runtime/vendor/flywheel-cli-dist/commands/help-metadata.js.map +1 -0
- package/src/runtime/vendor/flywheel-cli-dist/commands/help.d.ts +2 -13
- package/src/runtime/vendor/flywheel-cli-dist/commands/help.js +6 -128
- package/src/runtime/vendor/flywheel-cli-dist/commands/help.js.map +1 -1
- package/src/runtime/vendor/flywheel-cli-dist/commands/registry.d.ts +1 -0
- package/src/runtime/vendor/flywheel-cli-dist/commands/registry.js.map +1 -1
- package/src/runtime/vendor/flywheel-cli-dist/commands/usage-spec.d.ts +6 -0
- package/src/runtime/vendor/flywheel-cli-dist/commands/usage-spec.js +342 -0
- package/src/runtime/vendor/flywheel-cli-dist/commands/usage-spec.js.map +1 -0
- package/src/runtime/vendor/flywheel-cli-dist/main.js +129 -2
- package/src/runtime/vendor/flywheel-cli-dist/main.js.map +1 -1
- package/src/runtime/vendor/manifest.json +7 -1
- package/src/unified-cli.mjs +23 -46
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { CLI_VERSION } from '../version.js';
|
|
2
|
+
import { RUNTIME_ALIASES } from './aliases.js';
|
|
3
|
+
import { collectCommandMetadata, normalizeCommandMetadata, TOPIC_ORDER, } from './help-metadata.js';
|
|
4
|
+
const CLI_NAME = 'Flywheel CLI';
|
|
5
|
+
const CLI_BIN = 'flywheel';
|
|
6
|
+
const CLI_ABOUT = 'Inspect, organize, and operate Flywheel research graphs from the command line.';
|
|
7
|
+
const ROOT_FLAGS = [
|
|
8
|
+
{
|
|
9
|
+
name: 'help',
|
|
10
|
+
type: 'boolean',
|
|
11
|
+
usage: '-h --help',
|
|
12
|
+
description: 'Show this help.',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'version',
|
|
16
|
+
type: 'boolean',
|
|
17
|
+
usage: '-v --version',
|
|
18
|
+
description: 'Print the Flywheel CLI version.',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'usage',
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
description: 'Print the public Usage/KDL command specification.',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'usage-spec',
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
description: 'Print the public Usage/KDL command specification.',
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
const ROOT_COMMANDS = [
|
|
32
|
+
{
|
|
33
|
+
name: 'help',
|
|
34
|
+
summary: 'Show Flywheel CLI help.',
|
|
35
|
+
args: [
|
|
36
|
+
{
|
|
37
|
+
usage: '[command]',
|
|
38
|
+
description: 'Command name to inspect.',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
flags: [
|
|
42
|
+
{
|
|
43
|
+
name: 'aliases',
|
|
44
|
+
type: 'boolean',
|
|
45
|
+
usage: '-a --aliases',
|
|
46
|
+
description: 'List public command shortcuts.',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'format',
|
|
50
|
+
type: 'string',
|
|
51
|
+
usage: '--format <FORMAT>',
|
|
52
|
+
description: 'Output help metadata as JSON.',
|
|
53
|
+
choices: ['json'],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'schema',
|
|
57
|
+
type: 'boolean',
|
|
58
|
+
description: 'Print a minimal JSON payload schema for supported commands.',
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'version',
|
|
64
|
+
summary: 'Print the Flywheel CLI version.',
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
const RUNTIME_GLOBAL_FLAGS = [
|
|
68
|
+
{
|
|
69
|
+
name: 'format',
|
|
70
|
+
type: 'string',
|
|
71
|
+
usage: '--format <FORMAT>',
|
|
72
|
+
description: 'Output format for command results.',
|
|
73
|
+
choices: ['json', 'tsv', 'csv', 'table'],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'env',
|
|
77
|
+
type: 'string',
|
|
78
|
+
usage: '--env <PROFILE>',
|
|
79
|
+
description: 'Use a configured CLI profile for this invocation.',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'out',
|
|
83
|
+
type: 'string',
|
|
84
|
+
usage: '--out <PATH>',
|
|
85
|
+
description: 'Write output to a file path, or use - for stdout.',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: 'open',
|
|
89
|
+
type: 'boolean',
|
|
90
|
+
description: 'Open browser-bound URLs when supported.',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'no-retry',
|
|
94
|
+
type: 'boolean',
|
|
95
|
+
description: 'Disable transient-error retries.',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'retry-max',
|
|
99
|
+
type: 'integer',
|
|
100
|
+
usage: '--retry-max <N>',
|
|
101
|
+
description: 'Maximum transient-error retry attempts.',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'wait',
|
|
105
|
+
type: 'boolean',
|
|
106
|
+
description: 'Block on async operations until a terminal state is reached.',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: 'wait-timeout',
|
|
110
|
+
type: 'integer',
|
|
111
|
+
usage: '--wait-timeout <SECONDS>',
|
|
112
|
+
description: 'Seconds to wait for --wait before timing out. Defaults to 600.',
|
|
113
|
+
default: '600',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: 'allow-self',
|
|
117
|
+
type: 'boolean',
|
|
118
|
+
description: 'Allow mutating the currently active credential.',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: 'timeout',
|
|
122
|
+
type: 'integer',
|
|
123
|
+
usage: '--timeout <SECONDS>',
|
|
124
|
+
description: 'Set per-request HTTP timeout in seconds.',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: 'idempotency-key',
|
|
128
|
+
type: 'string',
|
|
129
|
+
usage: '--idempotency-key <KEY>',
|
|
130
|
+
description: 'Use a caller-supplied Idempotency-Key for write requests.',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: 'force',
|
|
134
|
+
type: 'boolean',
|
|
135
|
+
description: 'Force safety-gated operations where supported.',
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: 'yes',
|
|
139
|
+
type: 'boolean',
|
|
140
|
+
description: 'Skip confirmation prompts for destructive operations.',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: 'debug',
|
|
144
|
+
type: 'boolean',
|
|
145
|
+
description: 'Print structured request debugging with secrets masked.',
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: 'verbose',
|
|
149
|
+
type: 'boolean',
|
|
150
|
+
description: 'Print verbose progress for long-running operations.',
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: 'help',
|
|
154
|
+
type: 'boolean',
|
|
155
|
+
usage: '-h --help',
|
|
156
|
+
description: 'Show this help.',
|
|
157
|
+
},
|
|
158
|
+
];
|
|
159
|
+
const TOPIC_RANK = new Map(TOPIC_ORDER.map((topic, index) => [topic.id, index]));
|
|
160
|
+
const RUNTIME_ALIASES_BY_COMMAND = new Map();
|
|
161
|
+
for (const [alias, command] of Object.entries(RUNTIME_ALIASES)) {
|
|
162
|
+
const aliases = RUNTIME_ALIASES_BY_COMMAND.get(command) ?? [];
|
|
163
|
+
aliases.push(alias);
|
|
164
|
+
RUNTIME_ALIASES_BY_COMMAND.set(command, aliases);
|
|
165
|
+
}
|
|
166
|
+
function kdlString(value) {
|
|
167
|
+
return JSON.stringify(value);
|
|
168
|
+
}
|
|
169
|
+
function flagUsage(param) {
|
|
170
|
+
if (param.usage) {
|
|
171
|
+
return param.usage;
|
|
172
|
+
}
|
|
173
|
+
if (param.type === 'boolean') {
|
|
174
|
+
return `--${param.name}`;
|
|
175
|
+
}
|
|
176
|
+
return `--${param.name} <${param.type}>`;
|
|
177
|
+
}
|
|
178
|
+
function renderFlag(param, required, indent = ' ') {
|
|
179
|
+
const attrs = [`help=${kdlString(param.description)}`];
|
|
180
|
+
if (required) {
|
|
181
|
+
attrs.push('required=#true');
|
|
182
|
+
}
|
|
183
|
+
if (param.default) {
|
|
184
|
+
attrs.push(`default=${kdlString(param.default)}`);
|
|
185
|
+
}
|
|
186
|
+
if (!param.choices) {
|
|
187
|
+
return [`${indent}flag ${kdlString(flagUsage(param))} ${attrs.join(' ')}`];
|
|
188
|
+
}
|
|
189
|
+
return [
|
|
190
|
+
`${indent}flag ${kdlString(flagUsage(param))} ${attrs.join(' ')} {`,
|
|
191
|
+
`${indent} choices ${param.choices.map(kdlString).join(' ')}`,
|
|
192
|
+
`${indent}}`,
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
function renderRootArg(arg, indent = ' ') {
|
|
196
|
+
const attrs = [`help=${kdlString(arg.description)}`];
|
|
197
|
+
if (!arg.choices) {
|
|
198
|
+
return [`${indent}arg ${kdlString(arg.usage)} ${attrs.join(' ')}`];
|
|
199
|
+
}
|
|
200
|
+
return [
|
|
201
|
+
`${indent}arg ${kdlString(arg.usage)} ${attrs.join(' ')} {`,
|
|
202
|
+
`${indent} choices ${arg.choices.map(kdlString).join(' ')}`,
|
|
203
|
+
`${indent}}`,
|
|
204
|
+
];
|
|
205
|
+
}
|
|
206
|
+
function renderRootCommand(command) {
|
|
207
|
+
const args = command.args ?? [];
|
|
208
|
+
const flags = command.flags ?? [];
|
|
209
|
+
if (args.length === 0 && flags.length === 0) {
|
|
210
|
+
return [`cmd ${kdlString(command.name)} help=${kdlString(command.summary)}`];
|
|
211
|
+
}
|
|
212
|
+
const lines = [`cmd ${kdlString(command.name)} help=${kdlString(command.summary)} {`];
|
|
213
|
+
for (const arg of args) {
|
|
214
|
+
lines.push(...renderRootArg(arg));
|
|
215
|
+
}
|
|
216
|
+
for (const flag of flags) {
|
|
217
|
+
lines.push(...renderFlag(flag, false));
|
|
218
|
+
}
|
|
219
|
+
lines.push('}');
|
|
220
|
+
return lines;
|
|
221
|
+
}
|
|
222
|
+
function helpTargetChoices(commands) {
|
|
223
|
+
const choices = [];
|
|
224
|
+
const seen = new Set();
|
|
225
|
+
const pushChoice = (choice) => {
|
|
226
|
+
if (seen.has(choice))
|
|
227
|
+
return;
|
|
228
|
+
seen.add(choice);
|
|
229
|
+
choices.push(choice);
|
|
230
|
+
};
|
|
231
|
+
for (const command of commands) {
|
|
232
|
+
pushChoice(command.name);
|
|
233
|
+
for (const alias of RUNTIME_ALIASES_BY_COMMAND.get(command.name) ?? []) {
|
|
234
|
+
pushChoice(alias);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return choices;
|
|
238
|
+
}
|
|
239
|
+
function rootCommandsWithHelpTargetChoices(commands) {
|
|
240
|
+
const choices = helpTargetChoices(commands);
|
|
241
|
+
return ROOT_COMMANDS.map((command) => {
|
|
242
|
+
if (command.name !== 'help')
|
|
243
|
+
return command;
|
|
244
|
+
return {
|
|
245
|
+
...command,
|
|
246
|
+
args: command.args?.map((arg) => arg.usage === '[command]' ? { ...arg, choices } : arg),
|
|
247
|
+
};
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
function renderArg(param, indent = ' ') {
|
|
251
|
+
const attrs = [`help=${kdlString(param.description)}`];
|
|
252
|
+
if (param.default) {
|
|
253
|
+
attrs.push(`default=${kdlString(param.default)}`);
|
|
254
|
+
}
|
|
255
|
+
if (!param.choices) {
|
|
256
|
+
return [`${indent}arg ${kdlString(param.name)} ${attrs.join(' ')}`];
|
|
257
|
+
}
|
|
258
|
+
return [
|
|
259
|
+
`${indent}arg ${kdlString(param.name)} ${attrs.join(' ')} {`,
|
|
260
|
+
`${indent} choices ${param.choices.map(kdlString).join(' ')}`,
|
|
261
|
+
`${indent}}`,
|
|
262
|
+
];
|
|
263
|
+
}
|
|
264
|
+
function renderCommand(metadata, options) {
|
|
265
|
+
const command = normalizeCommandMetadata(metadata);
|
|
266
|
+
const lines = [`cmd ${kdlString(command.name)} help=${kdlString(command.summary)} {`];
|
|
267
|
+
for (const alias of options.aliases) {
|
|
268
|
+
lines.push(` alias ${kdlString(alias)}`);
|
|
269
|
+
}
|
|
270
|
+
for (const arg of command.args) {
|
|
271
|
+
lines.push(...renderArg(arg));
|
|
272
|
+
}
|
|
273
|
+
for (const param of command.required) {
|
|
274
|
+
lines.push(...renderFlag(param, true));
|
|
275
|
+
}
|
|
276
|
+
for (const param of command.optional) {
|
|
277
|
+
lines.push(...renderFlag(param, false));
|
|
278
|
+
}
|
|
279
|
+
if (options.runtimeGlobals) {
|
|
280
|
+
for (const flag of RUNTIME_GLOBAL_FLAGS) {
|
|
281
|
+
lines.push(...renderFlag(flag, false));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
for (const example of command.examples) {
|
|
285
|
+
lines.push(` example ${kdlString(example.invocation)} help=${kdlString(example.description)}`);
|
|
286
|
+
}
|
|
287
|
+
lines.push('}');
|
|
288
|
+
return lines;
|
|
289
|
+
}
|
|
290
|
+
function sortCommands(commands) {
|
|
291
|
+
return [...commands].sort((a, b) => {
|
|
292
|
+
const topicCmp = (TOPIC_RANK.get(a.group) ?? Number.MAX_SAFE_INTEGER) -
|
|
293
|
+
(TOPIC_RANK.get(b.group) ?? Number.MAX_SAFE_INTEGER);
|
|
294
|
+
if (topicCmp !== 0)
|
|
295
|
+
return topicCmp;
|
|
296
|
+
return a.name.localeCompare(b.name);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
export function renderUsageSpec(extrasOrOptions = []) {
|
|
300
|
+
let extras;
|
|
301
|
+
let version;
|
|
302
|
+
if (Array.isArray(extrasOrOptions)) {
|
|
303
|
+
extras = extrasOrOptions;
|
|
304
|
+
version = CLI_VERSION;
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
const options = extrasOrOptions;
|
|
308
|
+
extras = options.extras ?? [];
|
|
309
|
+
version = options.version ?? CLI_VERSION;
|
|
310
|
+
}
|
|
311
|
+
const runtimeCommandNames = new Set(collectCommandMetadata({
|
|
312
|
+
internal: false,
|
|
313
|
+
adminDiscovery: false,
|
|
314
|
+
extras: [],
|
|
315
|
+
}).map((command) => command.name));
|
|
316
|
+
const commands = sortCommands(collectCommandMetadata({
|
|
317
|
+
internal: false,
|
|
318
|
+
adminDiscovery: false,
|
|
319
|
+
extras,
|
|
320
|
+
}));
|
|
321
|
+
const lines = [
|
|
322
|
+
`name ${kdlString(CLI_NAME)}`,
|
|
323
|
+
`bin ${kdlString(CLI_BIN)}`,
|
|
324
|
+
`about ${kdlString(CLI_ABOUT)}`,
|
|
325
|
+
`version ${kdlString(version)}`,
|
|
326
|
+
];
|
|
327
|
+
for (const flag of ROOT_FLAGS) {
|
|
328
|
+
lines.push(...renderFlag(flag, false, ''));
|
|
329
|
+
}
|
|
330
|
+
lines.push('');
|
|
331
|
+
for (const command of rootCommandsWithHelpTargetChoices(commands)) {
|
|
332
|
+
lines.push(...renderRootCommand(command), '');
|
|
333
|
+
}
|
|
334
|
+
for (const command of commands) {
|
|
335
|
+
lines.push(...renderCommand(command, {
|
|
336
|
+
runtimeGlobals: runtimeCommandNames.has(command.name),
|
|
337
|
+
aliases: RUNTIME_ALIASES_BY_COMMAND.get(command.name) ?? [],
|
|
338
|
+
}), '');
|
|
339
|
+
}
|
|
340
|
+
return `${lines.join('\n').trimEnd()}\n`;
|
|
341
|
+
}
|
|
342
|
+
//# sourceMappingURL=usage-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,KAAK,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,MAAM,OAAO,IAAI,iCAAiC,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClE,KAAK,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IAChD,CAAC;IACD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CACR,GAAG,aAAa,CAAC,OAAO,EAAE;YACxB,cAAc,EAAE,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;YACrD,OAAO,EAAE,0BAA0B,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE;SAC5D,CAAC,EACF,EAAE,CACH,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC;AAC3C,CAAC"}
|
|
@@ -11,6 +11,7 @@ import { loadProfile } from './auth/profile.js';
|
|
|
11
11
|
import { RUNTIME_ALIASES } from './commands/aliases.js';
|
|
12
12
|
import { BUILTIN_PROFILE_NAMES, isBuiltinProfileName, resolveBuiltinBaseUrl, } from './auth/profiles.js';
|
|
13
13
|
import { renderCommandHelp, renderCommandHelpAsJson, renderHelp, renderHelpAsJson, } from './commands/help.js';
|
|
14
|
+
import { renderUsageSpec } from './commands/usage-spec.js';
|
|
14
15
|
import { getCommandByName } from './commands/registry.js';
|
|
15
16
|
import { MVP_COMMAND_HANDLERS } from './commands/index.js';
|
|
16
17
|
import { CliApprovalPendingError, CliAuthRequirementError, CliFinalizeFailedError, CliUsageError, CliWaitTimeoutError, } from './errors.js';
|
|
@@ -142,8 +143,11 @@ async function resolveRuntimeAuthConfig(config, profile, resolveEnvApiKey) {
|
|
|
142
143
|
};
|
|
143
144
|
}
|
|
144
145
|
const HELP_TOKENS = new Set(['--help', '-h']);
|
|
146
|
+
const USAGE_TOKENS = new Set(['--usage', '--usage-spec']);
|
|
145
147
|
const SCHEMA_TOKEN = '--schema';
|
|
146
148
|
const HELP_EXTRAS_PREFIX = '--_help_extras=';
|
|
149
|
+
const USAGE_EXTRAS_PREFIX = '--_usage_extras=';
|
|
150
|
+
const USAGE_VERSION_PREFIX = '--_usage_version=';
|
|
147
151
|
const VALID_TOPIC_IDS = new Set([
|
|
148
152
|
'setup-admin',
|
|
149
153
|
'auth',
|
|
@@ -202,6 +206,80 @@ function parseHelpExtras(argv) {
|
|
|
202
206
|
function stripHelpExtras(argv) {
|
|
203
207
|
return argv.filter((t) => !t.startsWith(HELP_EXTRAS_PREFIX));
|
|
204
208
|
}
|
|
209
|
+
function isStringArray(value) {
|
|
210
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === 'string');
|
|
211
|
+
}
|
|
212
|
+
function isCommandParamArray(value) {
|
|
213
|
+
return (Array.isArray(value) &&
|
|
214
|
+
value.every((entry) => {
|
|
215
|
+
if (!entry || typeof entry !== 'object')
|
|
216
|
+
return false;
|
|
217
|
+
const candidate = entry;
|
|
218
|
+
return (typeof candidate.name === 'string' &&
|
|
219
|
+
['string', 'integer', 'json', 'boolean'].includes(String(candidate.type)) &&
|
|
220
|
+
typeof candidate.description === 'string' &&
|
|
221
|
+
(candidate.default === undefined || typeof candidate.default === 'string'));
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
function isCommandExampleArray(value) {
|
|
225
|
+
return (Array.isArray(value) &&
|
|
226
|
+
value.every((entry) => {
|
|
227
|
+
if (!entry || typeof entry !== 'object')
|
|
228
|
+
return false;
|
|
229
|
+
const candidate = entry;
|
|
230
|
+
return (typeof candidate.description === 'string' &&
|
|
231
|
+
typeof candidate.invocation === 'string');
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
function isUsageExtra(value) {
|
|
235
|
+
if (!value || typeof value !== 'object')
|
|
236
|
+
return false;
|
|
237
|
+
const candidate = value;
|
|
238
|
+
return (typeof candidate.name === 'string' &&
|
|
239
|
+
typeof candidate.group === 'string' &&
|
|
240
|
+
VALID_TOPIC_IDS.has(candidate.group) &&
|
|
241
|
+
typeof candidate.summary === 'string' &&
|
|
242
|
+
(candidate.endpoints === undefined || isStringArray(candidate.endpoints)) &&
|
|
243
|
+
(candidate.required === undefined || isCommandParamArray(candidate.required)) &&
|
|
244
|
+
(candidate.optional === undefined || isCommandParamArray(candidate.optional)) &&
|
|
245
|
+
(candidate.examples === undefined || isCommandExampleArray(candidate.examples)) &&
|
|
246
|
+
(candidate.related === undefined || isStringArray(candidate.related)) &&
|
|
247
|
+
(candidate.schema === undefined || typeof candidate.schema === 'string') &&
|
|
248
|
+
(candidate.hidden === undefined || typeof candidate.hidden === 'boolean'));
|
|
249
|
+
}
|
|
250
|
+
function parseUsageExtras(argv) {
|
|
251
|
+
const rawValues = argv
|
|
252
|
+
.filter((token) => token.startsWith(USAGE_EXTRAS_PREFIX))
|
|
253
|
+
.map((token) => token.slice(USAGE_EXTRAS_PREFIX.length));
|
|
254
|
+
const rawVersionValues = argv
|
|
255
|
+
.filter((token) => token.startsWith(USAGE_VERSION_PREFIX))
|
|
256
|
+
.map((token) => token.slice(USAGE_VERSION_PREFIX.length));
|
|
257
|
+
if (rawValues.length === 0 && rawVersionValues.length === 0) {
|
|
258
|
+
return { kind: 'ok', extras: [] };
|
|
259
|
+
}
|
|
260
|
+
if (rawValues.length > 1)
|
|
261
|
+
return { kind: 'invalid' };
|
|
262
|
+
if (rawVersionValues.length > 1)
|
|
263
|
+
return { kind: 'invalid' };
|
|
264
|
+
const version = rawVersionValues[0];
|
|
265
|
+
if (version !== undefined && version.trim() === '')
|
|
266
|
+
return { kind: 'invalid' };
|
|
267
|
+
let extras = [];
|
|
268
|
+
if (rawValues.length === 1) {
|
|
269
|
+
let decoded;
|
|
270
|
+
try {
|
|
271
|
+
decoded = JSON.parse(rawValues[0]);
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return { kind: 'invalid' };
|
|
275
|
+
}
|
|
276
|
+
if (!Array.isArray(decoded) || !decoded.every(isUsageExtra)) {
|
|
277
|
+
return { kind: 'invalid' };
|
|
278
|
+
}
|
|
279
|
+
extras = decoded;
|
|
280
|
+
}
|
|
281
|
+
return { kind: 'ok', extras, version };
|
|
282
|
+
}
|
|
205
283
|
// Commands that do not touch the HTTP runtime and therefore must run even
|
|
206
284
|
// when ~/.config/flywheel-cli/config.json is absent. These are purely local
|
|
207
285
|
// state operations (profile bookkeeping, keychain reads/writes) plus the
|
|
@@ -300,6 +378,28 @@ function stripFormatTokens(argv) {
|
|
|
300
378
|
}
|
|
301
379
|
return out;
|
|
302
380
|
}
|
|
381
|
+
function normalizeCommandHelpArgs(argv) {
|
|
382
|
+
let schema = false;
|
|
383
|
+
let aliases = false;
|
|
384
|
+
const commandArgs = [];
|
|
385
|
+
for (const token of argv) {
|
|
386
|
+
if (token === SCHEMA_TOKEN) {
|
|
387
|
+
schema = true;
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (token === '--aliases' || token === '-a') {
|
|
391
|
+
aliases = true;
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
commandArgs.push(token);
|
|
395
|
+
}
|
|
396
|
+
return { commandArgs, schema, aliases };
|
|
397
|
+
}
|
|
398
|
+
function renderAliasesHelp() {
|
|
399
|
+
return `${Object.entries(RUNTIME_ALIASES)
|
|
400
|
+
.map(([aliasCommand, canonicalCommand]) => ` ${aliasCommand} → ${canonicalCommand}`)
|
|
401
|
+
.join('\n')}\n`;
|
|
402
|
+
}
|
|
303
403
|
function emitCommandHelp(stdout, stderr, commandName, schema, asJson) {
|
|
304
404
|
if (asJson) {
|
|
305
405
|
const payload = renderCommandHelpAsJson(commandName);
|
|
@@ -466,6 +566,26 @@ export async function runCli(argv, dependencies = {}) {
|
|
|
466
566
|
}
|
|
467
567
|
argv = rewriteAlias(argv);
|
|
468
568
|
const [first, ...rest] = argv;
|
|
569
|
+
if (USAGE_TOKENS.has(first)) {
|
|
570
|
+
const extrasParsed = parseUsageExtras(argv);
|
|
571
|
+
if (extrasParsed.kind === 'invalid') {
|
|
572
|
+
writeLine(stderr, 'invalid --_usage_extras payload');
|
|
573
|
+
return EXIT_USAGE;
|
|
574
|
+
}
|
|
575
|
+
stdout(renderUsageSpec({
|
|
576
|
+
extras: extrasParsed.extras,
|
|
577
|
+
version: extrasParsed.version,
|
|
578
|
+
}));
|
|
579
|
+
return 0;
|
|
580
|
+
}
|
|
581
|
+
const usagePrivateFlag = argv.find((token) => token.startsWith(USAGE_EXTRAS_PREFIX) ||
|
|
582
|
+
token.startsWith(USAGE_VERSION_PREFIX));
|
|
583
|
+
if (usagePrivateFlag !== undefined) {
|
|
584
|
+
writeLine(stderr, usagePrivateFlag.startsWith(USAGE_VERSION_PREFIX)
|
|
585
|
+
? 'unknown flag: --_usage_version'
|
|
586
|
+
: 'unknown flag: --_usage_extras');
|
|
587
|
+
return EXIT_USAGE;
|
|
588
|
+
}
|
|
469
589
|
// Help-format validation intentionally runs only inside the help branches
|
|
470
590
|
// below. Non-help commands let `parseCliArgs` validate --format against the
|
|
471
591
|
// full json|tsv|csv|table set; validating here would reject legitimate
|
|
@@ -504,12 +624,20 @@ export async function runCli(argv, dependencies = {}) {
|
|
|
504
624
|
return resolved;
|
|
505
625
|
// Strip --format and --_help_extras tokens so the positional <command>
|
|
506
626
|
// lookup isn't fooled by them occupying rest[0].
|
|
507
|
-
const helpArgs = stripHelpExtras(stripFormatTokens(rest));
|
|
627
|
+
const { commandArgs: helpArgs, schema, aliases } = normalizeCommandHelpArgs(stripHelpExtras(stripFormatTokens(rest)));
|
|
508
628
|
const extrasParsed = parseHelpExtras(argv);
|
|
509
629
|
if (extrasParsed.kind === 'invalid') {
|
|
510
630
|
writeLine(stderr, 'invalid --_help_extras payload');
|
|
511
631
|
return EXIT_USAGE;
|
|
512
632
|
}
|
|
633
|
+
if (schema && helpArgs.length === 0) {
|
|
634
|
+
writeLine(stderr, '--schema requires a command name');
|
|
635
|
+
return EXIT_USAGE;
|
|
636
|
+
}
|
|
637
|
+
if (aliases) {
|
|
638
|
+
stdout(renderAliasesHelp());
|
|
639
|
+
return 0;
|
|
640
|
+
}
|
|
513
641
|
if (helpArgs.length === 0) {
|
|
514
642
|
const extras = extrasParsed.kind === 'ok' ? extrasParsed.extras : [];
|
|
515
643
|
stdout(resolved.json ? renderHelpAsJson(extras) : renderHelp(extras));
|
|
@@ -527,7 +655,6 @@ export async function runCli(argv, dependencies = {}) {
|
|
|
527
655
|
const commandName = Object.prototype.hasOwnProperty.call(RUNTIME_ALIASES, rawCommandName)
|
|
528
656
|
? RUNTIME_ALIASES[rawCommandName]
|
|
529
657
|
: rawCommandName;
|
|
530
|
-
const schema = helpArgs.slice(1).includes(SCHEMA_TOKEN);
|
|
531
658
|
return emitCommandHelp(stdout, stderr, commandName, schema, resolved.json);
|
|
532
659
|
}
|
|
533
660
|
// --_help_extras is reserved for top-level help dispatch only. Reject it
|