@jackwener/opencli 1.7.13 → 1.7.14
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/cli-manifest.json +112 -0
- package/clis/twitter/quote.js +139 -0
- package/clis/twitter/quote.test.js +106 -0
- package/clis/twitter/retweet.js +99 -0
- package/clis/twitter/retweet.test.js +69 -0
- package/clis/twitter/shared.js +38 -0
- package/clis/twitter/shared.test.js +28 -1
- package/clis/twitter/unlike.js +87 -0
- package/clis/twitter/unlike.test.js +72 -0
- package/clis/twitter/unretweet.js +99 -0
- package/clis/twitter/unretweet.test.js +69 -0
- package/dist/src/browser/bridge.js +47 -45
- package/dist/src/browser.test.js +18 -0
- package/dist/src/cli.test.js +91 -1
- package/dist/src/commanderAdapter.js +23 -4
- package/dist/src/help.d.ts +4 -0
- package/dist/src/help.js +156 -5
- package/package.json +1 -1
package/dist/src/help.js
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
import yaml from 'js-yaml';
|
|
2
2
|
import { fullName } from './registry.js';
|
|
3
3
|
import { formatCommandExample } from './serialization.js';
|
|
4
|
+
const COMMON_OPTIONS = [
|
|
5
|
+
{
|
|
6
|
+
flags: '-f, --format <fmt>',
|
|
7
|
+
name: 'format',
|
|
8
|
+
help: 'Output format: table, plain, json, yaml, md, csv',
|
|
9
|
+
default: 'table',
|
|
10
|
+
choices: ['table', 'plain', 'json', 'yaml', 'md', 'csv'],
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
flags: '--trace <mode>',
|
|
14
|
+
name: 'trace',
|
|
15
|
+
help: 'Trace capture: off, on, retain-on-failure',
|
|
16
|
+
default: 'off',
|
|
17
|
+
choices: ['off', 'on', 'retain-on-failure'],
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
flags: '-v, --verbose',
|
|
21
|
+
name: 'verbose',
|
|
22
|
+
help: 'Debug output',
|
|
23
|
+
default: false,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
flags: '-h, --help',
|
|
27
|
+
name: 'help',
|
|
28
|
+
help: 'display help for command',
|
|
29
|
+
},
|
|
30
|
+
];
|
|
4
31
|
function normalizeStructuredHelpFormat(value) {
|
|
5
32
|
const normalized = value?.toLowerCase();
|
|
6
33
|
if (normalized === 'yaml' || normalized === 'yml')
|
|
@@ -73,7 +100,7 @@ export function formatRootAdapterHelpText(groups) {
|
|
|
73
100
|
lines.push(...formatGroupSection('App adapters', groups.apps));
|
|
74
101
|
lines.push(...formatGroupSection('Site adapters', groups.sites));
|
|
75
102
|
lines.push("Run 'opencli list' for full command details, or 'opencli <site> --help' to inspect one site.");
|
|
76
|
-
lines.push("Agent tip: use 'opencli <site> --help -f yaml' for
|
|
103
|
+
lines.push("Agent tip: use 'opencli <site> --help -f yaml' for all command args/options in one structured response.");
|
|
77
104
|
lines.push('');
|
|
78
105
|
return lines.join('\n');
|
|
79
106
|
}
|
|
@@ -89,18 +116,56 @@ function compactArg(arg) {
|
|
|
89
116
|
...(arg.help ? { help: arg.help } : {}),
|
|
90
117
|
};
|
|
91
118
|
}
|
|
92
|
-
function
|
|
119
|
+
function compactCommonOption(option) {
|
|
120
|
+
return {
|
|
121
|
+
name: option.name,
|
|
122
|
+
flags: option.flags,
|
|
123
|
+
help: option.help,
|
|
124
|
+
...('default' in option ? { default: option.default } : {}),
|
|
125
|
+
...('choices' in option ? { choices: option.choices } : {}),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function positionals(cmd) {
|
|
129
|
+
return cmd.args.filter(arg => arg.positional);
|
|
130
|
+
}
|
|
131
|
+
function commandOptions(cmd) {
|
|
132
|
+
return cmd.args.filter(arg => !arg.positional);
|
|
133
|
+
}
|
|
134
|
+
function formatPositionals(args) {
|
|
135
|
+
return args
|
|
136
|
+
.map(arg => arg.required ? `<${arg.name}>` : `[${arg.name}]`)
|
|
137
|
+
.join(' ');
|
|
138
|
+
}
|
|
139
|
+
function formatCommandOptionTerm(arg) {
|
|
140
|
+
if (arg.required || arg.valueRequired)
|
|
141
|
+
return `--${arg.name} <value>`;
|
|
142
|
+
return `--${arg.name} [value]`;
|
|
143
|
+
}
|
|
144
|
+
export function formatCommandListTerm(cmd) {
|
|
145
|
+
const positionalText = formatPositionals(positionals(cmd));
|
|
146
|
+
const optionText = commandOptions(cmd).length > 0 ? ' [options]' : '';
|
|
147
|
+
return `${cmd.name}${positionalText ? ` ${positionalText}` : ''}${optionText}`;
|
|
148
|
+
}
|
|
149
|
+
function formatUsage(cmd) {
|
|
150
|
+
const positionalText = formatPositionals(positionals(cmd));
|
|
151
|
+
return `opencli ${cmd.site} ${cmd.name}${positionalText ? ` ${positionalText}` : ''} [options]`;
|
|
152
|
+
}
|
|
153
|
+
function compactCommand(cmd) {
|
|
93
154
|
return {
|
|
94
155
|
name: cmd.name,
|
|
95
156
|
command: `opencli ${cmd.site} ${cmd.name}`,
|
|
157
|
+
usage: formatUsage(cmd),
|
|
96
158
|
access: cmd.access,
|
|
97
159
|
description: cmd.description,
|
|
160
|
+
browser: !!cmd.browser,
|
|
161
|
+
...(cmd.domain ? { domain: cmd.domain } : {}),
|
|
98
162
|
...(cmd.aliases?.length ? { aliases: cmd.aliases } : {}),
|
|
99
|
-
|
|
163
|
+
positionals: positionals(cmd).map(compactArg),
|
|
164
|
+
command_options: commandOptions(cmd).map(compactArg),
|
|
100
165
|
example: formatCommandExample(cmd),
|
|
101
166
|
...(cmd.browserSession ? { browserSession: cmd.browserSession } : {}),
|
|
102
167
|
...(cmd.defaultFormat ? { defaultFormat: cmd.defaultFormat } : {}),
|
|
103
|
-
...(
|
|
168
|
+
...(cmd.columns?.length ? { columns: cmd.columns } : {}),
|
|
104
169
|
};
|
|
105
170
|
}
|
|
106
171
|
export function rootHelpData(program, groups) {
|
|
@@ -142,6 +207,7 @@ export function siteHelpData(site, commands) {
|
|
|
142
207
|
site,
|
|
143
208
|
command_count: unique.length,
|
|
144
209
|
commands: unique.map(cmd => compactCommand(cmd)),
|
|
210
|
+
common_options: COMMON_OPTIONS.map(compactCommonOption),
|
|
145
211
|
next: [
|
|
146
212
|
`opencli ${site} <command> --help -f yaml`,
|
|
147
213
|
`opencli ${site} <command> -f yaml`,
|
|
@@ -151,10 +217,95 @@ export function siteHelpData(site, commands) {
|
|
|
151
217
|
export function commandHelpData(cmd) {
|
|
152
218
|
return {
|
|
153
219
|
site: cmd.site,
|
|
154
|
-
...compactCommand(cmd
|
|
220
|
+
...compactCommand(cmd),
|
|
221
|
+
common_options: COMMON_OPTIONS.map(compactCommonOption),
|
|
155
222
|
output_formats: ['table', 'plain', 'yaml', 'json', 'md', 'csv'],
|
|
156
223
|
};
|
|
157
224
|
}
|
|
225
|
+
function formatRows(rows) {
|
|
226
|
+
if (rows.length === 0)
|
|
227
|
+
return [];
|
|
228
|
+
const width = Math.min(Math.max(...rows.map(([left]) => left.length)), 34);
|
|
229
|
+
return rows.map(([left, right]) => ` ${left.padEnd(width + 2)}${right}`);
|
|
230
|
+
}
|
|
231
|
+
function formatArgHelp(arg) {
|
|
232
|
+
const parts = [];
|
|
233
|
+
if (arg.help)
|
|
234
|
+
parts.push(arg.help);
|
|
235
|
+
if (arg.default !== undefined)
|
|
236
|
+
parts.push(`default: ${arg.default}`);
|
|
237
|
+
if (arg.choices?.length)
|
|
238
|
+
parts.push(`choices: ${arg.choices.join(', ')}`);
|
|
239
|
+
return parts.join(' ');
|
|
240
|
+
}
|
|
241
|
+
export function formatCommonOptionsHelpText() {
|
|
242
|
+
const rows = COMMON_OPTIONS.map(option => {
|
|
243
|
+
const details = [option.help];
|
|
244
|
+
if ('default' in option)
|
|
245
|
+
details.push(`default: ${option.default}`);
|
|
246
|
+
if ('choices' in option)
|
|
247
|
+
details.push(`choices: ${option.choices.join(', ')}`);
|
|
248
|
+
return [option.flags, details.join(' ')];
|
|
249
|
+
});
|
|
250
|
+
return ['Common options:', ...formatRows(rows)].join('\n');
|
|
251
|
+
}
|
|
252
|
+
export function formatSiteHelpText(site, commands) {
|
|
253
|
+
const unique = [...new Map(commands.map(cmd => [fullName(cmd), cmd])).values()]
|
|
254
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
255
|
+
const lines = [
|
|
256
|
+
`Usage: opencli ${site} <command> [args] [options]`,
|
|
257
|
+
'',
|
|
258
|
+
wrapCommaList(unique.map(cmd => cmd.name), { indent: '' }),
|
|
259
|
+
'',
|
|
260
|
+
'Commands:',
|
|
261
|
+
...formatRows(unique.map(cmd => [formatCommandListTerm(cmd), formatSiteCommandDescription(cmd)])),
|
|
262
|
+
'',
|
|
263
|
+
formatCommonOptionsHelpText(),
|
|
264
|
+
'',
|
|
265
|
+
`Agent tip: use 'opencli ${site} --help -f yaml' to get all command args/options in one structured response.`,
|
|
266
|
+
'',
|
|
267
|
+
];
|
|
268
|
+
return lines.join('\n');
|
|
269
|
+
}
|
|
270
|
+
export function formatCommandHelpText(cmd) {
|
|
271
|
+
const lines = [
|
|
272
|
+
`Usage: ${formatUsage(cmd)}`,
|
|
273
|
+
'',
|
|
274
|
+
cmd.description,
|
|
275
|
+
'',
|
|
276
|
+
];
|
|
277
|
+
const positionalRows = positionals(cmd).map(arg => [
|
|
278
|
+
arg.name,
|
|
279
|
+
formatArgHelp(arg),
|
|
280
|
+
]);
|
|
281
|
+
if (positionalRows.length) {
|
|
282
|
+
lines.push('Arguments:', ...formatRows(positionalRows), '');
|
|
283
|
+
}
|
|
284
|
+
const optionRows = commandOptions(cmd).map(arg => [
|
|
285
|
+
formatCommandOptionTerm(arg),
|
|
286
|
+
formatArgHelp(arg),
|
|
287
|
+
]);
|
|
288
|
+
if (optionRows.length) {
|
|
289
|
+
lines.push('Command options:', ...formatRows(optionRows), '');
|
|
290
|
+
}
|
|
291
|
+
lines.push(formatCommonOptionsHelpText(), '');
|
|
292
|
+
const meta = [];
|
|
293
|
+
meta.push(`Access: ${cmd.access}`);
|
|
294
|
+
meta.push(`Browser: ${cmd.browser ? 'yes' : 'no'}`);
|
|
295
|
+
if (cmd.domain)
|
|
296
|
+
meta.push(`Domain: ${cmd.domain}`);
|
|
297
|
+
if (cmd.defaultFormat)
|
|
298
|
+
meta.push(`Default format: ${cmd.defaultFormat}`);
|
|
299
|
+
if (cmd.aliases?.length)
|
|
300
|
+
meta.push(`Aliases: ${cmd.aliases.join(', ')}`);
|
|
301
|
+
lines.push(meta.join(' | '));
|
|
302
|
+
lines.push(`Example: ${formatCommandExample(cmd)}`);
|
|
303
|
+
if (cmd.columns?.length)
|
|
304
|
+
lines.push(`Output columns: ${cmd.columns.join(', ')}`);
|
|
305
|
+
lines.push("Agent tip: use '--help -f yaml' for structured args/options.");
|
|
306
|
+
lines.push('');
|
|
307
|
+
return lines.join('\n');
|
|
308
|
+
}
|
|
158
309
|
export function installStructuredHelp(command, data, textSuffix) {
|
|
159
310
|
const original = command.helpInformation.bind(command);
|
|
160
311
|
command.helpInformation = ((contextOptions) => {
|