@hop-top/kit 0.5.0-alpha.4 → 0.5.0-alpha.5
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 +12 -0
- package/dist/{chunk-WTYDHXPW.js → chunk-ZC5TZYZJ.js} +53 -18
- package/dist/cli.js +3 -2
- package/dist/index.js +4 -4
- package/dist/output.js +4 -4
- package/package.json +1 -1
- package/src/cli.help-command.test.ts +105 -0
- package/src/cli.test.ts +39 -0
- package/src/cli.ts +54 -9
- package/dist/{chunk-UIOOOK6M.js → chunk-IXVQ62NZ.js} +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,18 @@ All notable changes to `@hop-top/kit` are documented in this file.
|
|
|
4
4
|
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/);
|
|
5
5
|
versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.5.0-alpha.5](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.4...kit-ts/v0.5.0-alpha.5) (2026-10-29)
|
|
8
|
+
|
|
9
|
+
The hop-top team is happy to announce Kit's TS SDK 0.5.0-alpha.5. This release includes maintenance release with bug fixes.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* **ts/cli:** render ARGUMENTS section in help ([ea98594](https://github.com/hop-top/poly-kit/commit/ea98594023b5082e965e476edf2148e68130d63d))
|
|
15
|
+
* **ts/cli:** route help <command> to command help ([6ce7c4c](https://github.com/hop-top/poly-kit/commit/6ce7c4c0f55a4b13359e4fa72c83414796664353))
|
|
16
|
+
|
|
17
|
+
Full diff: [kit-ts/v0.5.0-alpha.4...kit-ts/v0.5.0-alpha.5](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.4...kit-ts/v0.5.0-alpha.5)
|
|
18
|
+
|
|
7
19
|
## [0.5.0-alpha.4](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.3...kit-ts/v0.5.0-alpha.4) (2026-10-29)
|
|
8
20
|
|
|
9
21
|
The hop-top team is happy to announce Kit's TS SDK 0.5.0-alpha.4. This release includes new features and bug fixes.
|
|
@@ -6,6 +6,9 @@ var _chunkQPUCXQXTjs = require('./chunk-QPUCXQXT.js');
|
|
|
6
6
|
var _chunk72XZWQX7js = require('./chunk-72XZWQX7.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
+
var _chunkPOR5L2DGjs = require('./chunk-POR5L2DG.js');
|
|
10
|
+
|
|
11
|
+
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
|
|
@@ -341,6 +344,18 @@ function applyHelpTheme(program, theme, noColor, sectionOrder, showAliases, grou
|
|
|
341
344
|
output.push(helper.styleCommandDescription(desc));
|
|
342
345
|
output.push("");
|
|
343
346
|
}
|
|
347
|
+
const argList = helper.visibleArguments(cmd);
|
|
348
|
+
if (argList.length > 0) {
|
|
349
|
+
const title = _nullishCoalesce(_optionalChain([_chunkQPUCXQXTjs.parity, 'access', _10 => _10.help, 'access', _11 => _11.sections, 'optionalAccess', _12 => _12["arguments"], 'optionalAccess', _13 => _13.title]), () => ( "ARGUMENTS"));
|
|
350
|
+
output.push(helper.styleTitle(`${title}:`));
|
|
351
|
+
for (const a of argList) {
|
|
352
|
+
output.push(callFormatItem(
|
|
353
|
+
helper.styleArgumentTerm(helper.argumentTerm(a)),
|
|
354
|
+
helper.styleArgumentDescription(helper.argumentDescription(a))
|
|
355
|
+
));
|
|
356
|
+
}
|
|
357
|
+
output.push("");
|
|
358
|
+
}
|
|
344
359
|
const helpSections = [];
|
|
345
360
|
const helpAll = process.argv.includes("--help-all");
|
|
346
361
|
let helpGroupFilter;
|
|
@@ -413,7 +428,7 @@ function applyHelpTheme(program, theme, noColor, sectionOrder, showAliases, grou
|
|
|
413
428
|
const resolveTitle = (name) => {
|
|
414
429
|
const gdef = groupDefs.get(name);
|
|
415
430
|
if (gdef) return gdef.title;
|
|
416
|
-
return _nullishCoalesce(_optionalChain([sectionTitles, 'access',
|
|
431
|
+
return _nullishCoalesce(_optionalChain([sectionTitles, 'access', _14 => _14[name], 'optionalAccess', _15 => _15.title]), () => ( name.charAt(0).toUpperCase() + name.slice(1)));
|
|
417
432
|
};
|
|
418
433
|
for (const name of effectiveOrder) {
|
|
419
434
|
if (name === "flags") continue;
|
|
@@ -438,8 +453,8 @@ function applyHelpTheme(program, theme, noColor, sectionOrder, showAliases, grou
|
|
|
438
453
|
}
|
|
439
454
|
const defs = getStreamDefs(cmd);
|
|
440
455
|
if (defs.length > 0) {
|
|
441
|
-
const styleTerm = _nullishCoalesce(_optionalChain([helper, 'access',
|
|
442
|
-
const styleDesc = _nullishCoalesce(_optionalChain([helper, 'access',
|
|
456
|
+
const styleTerm = _nullishCoalesce(_optionalChain([helper, 'access', _16 => _16.styleOptionTerm, 'optionalAccess', _17 => _17.bind, 'call', _18 => _18(helper)]), () => ( ((s) => s)));
|
|
457
|
+
const styleDesc = _nullishCoalesce(_optionalChain([helper, 'access', _19 => _19.styleDescriptionText, 'optionalAccess', _20 => _20.bind, 'call', _21 => _21(helper)]), () => ( ((s) => s)));
|
|
443
458
|
output.push(helper.styleTitle("STREAMS:"));
|
|
444
459
|
for (const d of defs) {
|
|
445
460
|
output.push(callFormatItem(styleTerm(d.name), styleDesc(d.description)));
|
|
@@ -450,27 +465,37 @@ function applyHelpTheme(program, theme, noColor, sectionOrder, showAliases, grou
|
|
|
450
465
|
}
|
|
451
466
|
});
|
|
452
467
|
}
|
|
468
|
+
function findHelpTarget(root, operands) {
|
|
469
|
+
let cmd;
|
|
470
|
+
let scope = root;
|
|
471
|
+
for (const word of operands) {
|
|
472
|
+
cmd = scope.commands.find((c) => c.name() === word || c.aliases().includes(word));
|
|
473
|
+
if (!cmd) return void 0;
|
|
474
|
+
scope = cmd;
|
|
475
|
+
}
|
|
476
|
+
return cmd;
|
|
477
|
+
}
|
|
453
478
|
function createCLI(cfg) {
|
|
454
479
|
const theme = buildTheme(cfg.accent);
|
|
455
|
-
const desc = _optionalChain([cfg, 'access',
|
|
480
|
+
const desc = _optionalChain([cfg, 'access', _22 => _22.help, 'optionalAccess', _23 => _23.disclaimer]) ? `${cfg.description}
|
|
456
481
|
|
|
457
482
|
${cfg.help.disclaimer}` : cfg.description;
|
|
458
483
|
const normalizedVersion = cfg.version.startsWith("v") ? cfg.version : `v${cfg.version}`;
|
|
459
484
|
const versionOutput = `${cfg.name} ${normalizedVersion}`;
|
|
460
485
|
const program = new (0, _commander.Command)(cfg.name).description(desc).version(versionOutput, "-v, --version", `Print ${cfg.name} version and exit`).helpOption("-h, --help", "Display help").addHelpCommand(false).showHelpAfterError(true);
|
|
461
|
-
if (!_optionalChain([cfg, 'access',
|
|
486
|
+
if (!_optionalChain([cfg, 'access', _24 => _24.disable, 'optionalAccess', _25 => _25.format])) {
|
|
462
487
|
_chunk72XZWQX7js.registerOutputFlags.call(void 0, program);
|
|
463
488
|
}
|
|
464
|
-
if (!_optionalChain([cfg, 'access',
|
|
489
|
+
if (!_optionalChain([cfg, 'access', _26 => _26.disable, 'optionalAccess', _27 => _27.quiet])) {
|
|
465
490
|
program.option("--quiet", "Suppress non-essential output", false);
|
|
466
491
|
}
|
|
467
|
-
if (!_optionalChain([cfg, 'access',
|
|
492
|
+
if (!_optionalChain([cfg, 'access', _28 => _28.disable, 'optionalAccess', _29 => _29.noColor])) {
|
|
468
493
|
program.option("--no-color", "Disable ANSI colour", false);
|
|
469
494
|
}
|
|
470
|
-
if (!_optionalChain([cfg, 'access',
|
|
495
|
+
if (!_optionalChain([cfg, 'access', _30 => _30.disable, 'optionalAccess', _31 => _31.hints])) {
|
|
471
496
|
program.option("--no-hints", "Suppress next-step hints after command output", false);
|
|
472
497
|
}
|
|
473
|
-
if (!_optionalChain([cfg, 'access',
|
|
498
|
+
if (!_optionalChain([cfg, 'access', _32 => _32.disable, 'optionalAccess', _33 => _33.offline])) {
|
|
474
499
|
program.option("--offline", "Disable network access", false);
|
|
475
500
|
_chunkKVG7YCTSjs.install.call(void 0, );
|
|
476
501
|
const stamp = (thisCmd) => {
|
|
@@ -491,7 +516,7 @@ ${cfg.help.disclaimer}` : cfg.description;
|
|
|
491
516
|
quietMap.set(thisCmd, quiet);
|
|
492
517
|
verboseCountMap.set(thisCmd, quiet ? 0 : _nullishCoalesce(opts.verbose, () => ( 0)));
|
|
493
518
|
});
|
|
494
|
-
if (_optionalChain([cfg, 'access',
|
|
519
|
+
if (_optionalChain([cfg, 'access', _34 => _34.groups, 'optionalAccess', _35 => _35.some, 'call', _36 => _36((g) => g.hidden)])) {
|
|
495
520
|
program.option("--help-all", "Show all commands including hidden groups");
|
|
496
521
|
program.on("option:help-all", () => {
|
|
497
522
|
program.help();
|
|
@@ -505,16 +530,26 @@ ${cfg.help.disclaimer}` : cfg.description;
|
|
|
505
530
|
}
|
|
506
531
|
if (cfg.groups && cfg.groups.length > 0) {
|
|
507
532
|
const groupIds = cfg.groups.map((g) => g.id);
|
|
508
|
-
const helpCmd = program.command("help [
|
|
509
|
-
if (
|
|
510
|
-
process.argv.push("--help-all");
|
|
533
|
+
const helpCmd = program.command("help [operands...]").description("Show help for a command or command group").action((operands) => {
|
|
534
|
+
if (operands.length === 0) {
|
|
511
535
|
program.help();
|
|
512
|
-
}
|
|
513
|
-
|
|
536
|
+
}
|
|
537
|
+
if (operands.length === 1 && operands[0] === "all") {
|
|
538
|
+
process.argv.push("--help-all");
|
|
514
539
|
program.help();
|
|
515
|
-
}
|
|
540
|
+
}
|
|
541
|
+
const target = findHelpTarget(program, operands);
|
|
542
|
+
if (target) {
|
|
543
|
+
target.help();
|
|
544
|
+
}
|
|
545
|
+
if (operands.length === 1 && groupIds.includes(operands[0])) {
|
|
546
|
+
process.argv.push(`--help-${operands[0]}`);
|
|
516
547
|
program.help();
|
|
517
548
|
}
|
|
549
|
+
program.error(
|
|
550
|
+
`error: unknown help topic '${operands.join(" ")}' for '${program.name()}'`,
|
|
551
|
+
{ exitCode: _chunkPOR5L2DGjs.EXIT_USAGE, code: "commander.unknownCommand" }
|
|
552
|
+
);
|
|
518
553
|
});
|
|
519
554
|
helpCmd.hideHelp = true;
|
|
520
555
|
helpCmd._hidden = true;
|
|
@@ -527,8 +562,8 @@ ${cfg.help.disclaimer}` : cfg.description;
|
|
|
527
562
|
program,
|
|
528
563
|
theme,
|
|
529
564
|
false,
|
|
530
|
-
_optionalChain([cfg, 'access',
|
|
531
|
-
_optionalChain([cfg, 'access',
|
|
565
|
+
_optionalChain([cfg, 'access', _37 => _37.help, 'optionalAccess', _38 => _38.sectionOrder]),
|
|
566
|
+
_optionalChain([cfg, 'access', _39 => _39.help, 'optionalAccess', _40 => _40.showAliases]),
|
|
532
567
|
cfg.groups
|
|
533
568
|
);
|
|
534
569
|
const existing = _nullishCoalesce(program._outputConfiguration, () => ( {}));
|
package/dist/cli.js
CHANGED
|
@@ -22,9 +22,10 @@
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
var
|
|
25
|
+
var _chunkZC5TZYZJjs = require('./chunk-ZC5TZYZJ.js');
|
|
26
26
|
require('./chunk-QPUCXQXT.js');
|
|
27
27
|
require('./chunk-72XZWQX7.js');
|
|
28
|
+
require('./chunk-POR5L2DG.js');
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
|
|
@@ -64,4 +65,4 @@ require('./chunk-R5U7XKVJ.js');
|
|
|
64
65
|
|
|
65
66
|
|
|
66
67
|
|
|
67
|
-
exports.Dark =
|
|
68
|
+
exports.Dark = _chunkZC5TZYZJjs.Dark; exports.ErrOffline = _chunkKVG7YCTSjs.ErrOffline; exports.HintSet = _chunkZC5TZYZJjs.HintSet; exports.Neon = _chunkZC5TZYZJjs.Neon; exports.OfflineError = _chunkKVG7YCTSjs.OfflineError; exports.active = _chunkZC5TZYZJjs.active; exports.applyHelpTheme = _chunkZC5TZYZJjs.applyHelpTheme; exports.buildTheme = _chunkZC5TZYZJjs.buildTheme; exports.channel = _chunkZC5TZYZJjs.channel; exports.createCLI = _chunkZC5TZYZJjs.createCLI; exports.getCommandGroup = _chunkZC5TZYZJjs.getCommandGroup; exports.getStreamDefs = _chunkZC5TZYZJjs.getStreamDefs; exports.guardFetch = _chunkKVG7YCTSjs.guardFetch; exports.hintsEnabled = _chunkZC5TZYZJjs.hintsEnabled; exports.isOffline = _chunkKVG7YCTSjs.isOffline; exports.isOfflineError = _chunkKVG7YCTSjs.isOfflineError; exports.isQuiet = _chunkZC5TZYZJjs.isQuiet; exports.registerStream = _chunkZC5TZYZJjs.registerStream; exports.registerUpgradeHints = _chunkZC5TZYZJjs.registerUpgradeHints; exports.registerVersionHints = _chunkZC5TZYZJjs.registerVersionHints; exports.renderHints = _chunkZC5TZYZJjs.renderHints; exports.setCommandGroup = _chunkZC5TZYZJjs.setCommandGroup; exports.streamFlagName = _chunkZC5TZYZJjs.streamFlagName; exports.streamLabel = _chunkZC5TZYZJjs.streamLabel; exports.streamOutput = _chunkZC5TZYZJjs.streamOutput; exports.verboseCount = _chunkZC5TZYZJjs.verboseCount; exports.verbosityFlagSpec = _chunkZC5TZYZJjs.verbosityFlagSpec; exports.verbosityShorthand = _chunkZC5TZYZJjs.verbosityShorthand; exports.withOffline = _chunkKVG7YCTSjs.withOffline;
|
package/dist/index.js
CHANGED
|
@@ -33,8 +33,7 @@ var _chunkWWUKGJB5js = require('./chunk-WWUKGJB5.js');
|
|
|
33
33
|
var _chunkT46YPHKNjs = require('./chunk-T46YPHKN.js');
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
var
|
|
37
|
-
require('./chunk-POR5L2DG.js');
|
|
36
|
+
var _chunkIXVQ62NZjs = require('./chunk-IXVQ62NZ.js');
|
|
38
37
|
|
|
39
38
|
|
|
40
39
|
var _chunkBDNNPRX6js = require('./chunk-BDNNPRX6.js');
|
|
@@ -68,9 +67,10 @@ var _chunkCSJWB6D3js = require('./chunk-CSJWB6D3.js');
|
|
|
68
67
|
var _chunkUKZIAQA7js = require('./chunk-UKZIAQA7.js');
|
|
69
68
|
|
|
70
69
|
|
|
71
|
-
var
|
|
70
|
+
var _chunkZC5TZYZJjs = require('./chunk-ZC5TZYZJ.js');
|
|
72
71
|
require('./chunk-QPUCXQXT.js');
|
|
73
72
|
require('./chunk-72XZWQX7.js');
|
|
73
|
+
require('./chunk-POR5L2DG.js');
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
var _chunkKVG7YCTSjs = require('./chunk-KVG7YCTS.js');
|
|
@@ -108,4 +108,4 @@ require('./chunk-R5U7XKVJ.js');
|
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
|
|
111
|
-
exports.aim = _chunkQJVSKKRQjs.aim_exports; exports.alias = _chunkS45UHXQFjs.alias_exports; exports.anthropic = _chunkT46YPHKNjs.llm_anthropic_exports; exports.api = _chunkCSJWB6D3js.api_exports; exports.auth = _chunkUKZIAQA7js.auth_exports; exports.cli =
|
|
111
|
+
exports.aim = _chunkQJVSKKRQjs.aim_exports; exports.alias = _chunkS45UHXQFjs.alias_exports; exports.anthropic = _chunkT46YPHKNjs.llm_anthropic_exports; exports.api = _chunkCSJWB6D3js.api_exports; exports.auth = _chunkUKZIAQA7js.auth_exports; exports.cli = _chunkZC5TZYZJjs.cli_exports; exports.config = _chunkIQXEISMCjs.config_exports; exports.errcorrect = _chunk3FIKGFKIjs.errcorrect_exports; exports.id = _chunkL23O2FFEjs.id_exports; exports.llm = _chunkPSFYJGDGjs.llm_exports; exports.mcp = _chunkJTMPNXVQjs.mcp_exports; exports.netpolicy = _chunkKVG7YCTSjs.netpolicy_exports; exports.openai = _chunkABQSE7AIjs.llm_openai_exports; exports.output = _chunkIXVQ62NZjs.output_exports; exports.progress = _chunkBDNNPRX6js.progress_exports; exports.provenance = _chunk6SVOHNICjs.provenance_exports; exports.routellm = _chunkMUIQVU6Ejs.routellm_exports; exports.rpc = _chunkWUOAQVOAjs.rpc_exports; exports.safety = _chunk6HFAEZ52js.safety_exports; exports.scope = _chunkWBVO43HUjs.scope_exports; exports.serve = _chunkMQXYDYRDjs.serve_exports; exports.stream = _chunkBRNEKPWXjs.stream_exports; exports.telemetry = _chunkYOBAUCVNjs.telemetry_exports; exports.tui = _chunkGGWJRWWAjs.tui_exports; exports.upgrade = _chunkWWUKGJB5js.upgrade_exports; exports.xdg = _chunk4UE5TCMQjs.xdg_exports;
|
package/dist/output.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkIXVQ62NZjs = require('./chunk-IXVQ62NZ.js');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
@@ -23,6 +23,7 @@ var _chunkUIOOOK6Mjs = require('./chunk-UIOOOK6M.js');
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
var _chunk72XZWQX7js = require('./chunk-72XZWQX7.js');
|
|
26
27
|
|
|
27
28
|
|
|
28
29
|
|
|
@@ -50,7 +51,6 @@ var _chunkUIOOOK6Mjs = require('./chunk-UIOOOK6M.js');
|
|
|
50
51
|
|
|
51
52
|
|
|
52
53
|
|
|
53
|
-
var _chunkPOR5L2DGjs = require('./chunk-POR5L2DG.js');
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
|
|
@@ -67,7 +67,7 @@ var _chunkPOR5L2DGjs = require('./chunk-POR5L2DG.js');
|
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
|
|
70
|
-
var
|
|
70
|
+
var _chunkPOR5L2DGjs = require('./chunk-POR5L2DG.js');
|
|
71
71
|
require('./chunk-R5U7XKVJ.js');
|
|
72
72
|
|
|
73
73
|
|
|
@@ -134,4 +134,4 @@ require('./chunk-R5U7XKVJ.js');
|
|
|
134
134
|
|
|
135
135
|
|
|
136
136
|
|
|
137
|
-
exports.CODE_CONFLICT = _chunkPOR5L2DGjs.CODE_CONFLICT; exports.CODE_CONSENT_REFUSED = _chunkPOR5L2DGjs.CODE_CONSENT_REFUSED; exports.CODE_GENERIC = _chunkPOR5L2DGjs.CODE_GENERIC; exports.CODE_NOT_FOUND = _chunkPOR5L2DGjs.CODE_NOT_FOUND; exports.CODE_OK = _chunkPOR5L2DGjs.CODE_OK; exports.CODE_PREREQUISITE = _chunkPOR5L2DGjs.CODE_PREREQUISITE; exports.CODE_PROVENANCE_MISSING = _chunkPOR5L2DGjs.CODE_PROVENANCE_MISSING; exports.CODE_RATE_LIMITED = _chunkPOR5L2DGjs.CODE_RATE_LIMITED; exports.CODE_TRANSIENT = _chunkPOR5L2DGjs.CODE_TRANSIENT; exports.CODE_UNAUTHORIZED = _chunkPOR5L2DGjs.CODE_UNAUTHORIZED; exports.CODE_USAGE = _chunkPOR5L2DGjs.CODE_USAGE; exports.CSV_FORMAT =
|
|
137
|
+
exports.CODE_CONFLICT = _chunkPOR5L2DGjs.CODE_CONFLICT; exports.CODE_CONSENT_REFUSED = _chunkPOR5L2DGjs.CODE_CONSENT_REFUSED; exports.CODE_GENERIC = _chunkPOR5L2DGjs.CODE_GENERIC; exports.CODE_NOT_FOUND = _chunkPOR5L2DGjs.CODE_NOT_FOUND; exports.CODE_OK = _chunkPOR5L2DGjs.CODE_OK; exports.CODE_PREREQUISITE = _chunkPOR5L2DGjs.CODE_PREREQUISITE; exports.CODE_PROVENANCE_MISSING = _chunkPOR5L2DGjs.CODE_PROVENANCE_MISSING; exports.CODE_RATE_LIMITED = _chunkPOR5L2DGjs.CODE_RATE_LIMITED; exports.CODE_TRANSIENT = _chunkPOR5L2DGjs.CODE_TRANSIENT; exports.CODE_UNAUTHORIZED = _chunkPOR5L2DGjs.CODE_UNAUTHORIZED; exports.CODE_USAGE = _chunkPOR5L2DGjs.CODE_USAGE; exports.CSV_FORMAT = _chunkIXVQ62NZjs.CSV_FORMAT; exports.EXIT_CONFLICT = _chunkPOR5L2DGjs.EXIT_CONFLICT; exports.EXIT_CONSENT_REFUSED = _chunkPOR5L2DGjs.EXIT_CONSENT_REFUSED; exports.EXIT_GENERIC = _chunkPOR5L2DGjs.EXIT_GENERIC; exports.EXIT_NOT_FOUND = _chunkPOR5L2DGjs.EXIT_NOT_FOUND; exports.EXIT_OK = _chunkPOR5L2DGjs.EXIT_OK; exports.EXIT_PREREQUISITE = _chunkPOR5L2DGjs.EXIT_PREREQUISITE; exports.EXIT_PROVENANCE_MISSING = _chunkPOR5L2DGjs.EXIT_PROVENANCE_MISSING; exports.EXIT_RATE_LIMITED = _chunkPOR5L2DGjs.EXIT_RATE_LIMITED; exports.EXIT_TRANSIENT = _chunkPOR5L2DGjs.EXIT_TRANSIENT; exports.EXIT_UNAUTHORIZED = _chunkPOR5L2DGjs.EXIT_UNAUTHORIZED; exports.EXIT_USAGE = _chunkPOR5L2DGjs.EXIT_USAGE; exports.JSON_FORMAT = _chunkIXVQ62NZjs.JSON_FORMAT; exports.Registry = _chunk72XZWQX7js.Registry; exports.TABLE_FORMAT = _chunkIXVQ62NZjs.TABLE_FORMAT; exports.TEXT_FORMAT = _chunkIXVQ62NZjs.TEXT_FORMAT; exports.TRANSIENCE_PERMANENT = _chunkPOR5L2DGjs.TRANSIENCE_PERMANENT; exports.TRANSIENCE_TRANSIENT = _chunkPOR5L2DGjs.TRANSIENCE_TRANSIENT; exports.TRANSIENCE_UNKNOWN = _chunkPOR5L2DGjs.TRANSIENCE_UNKNOWN; exports.YAML_FORMAT = _chunkIXVQ62NZjs.YAML_FORMAT; exports.columnName = _chunk72XZWQX7js.columnName; exports.conflictError = _chunkPOR5L2DGjs.conflictError; exports.consentRefusedError = _chunkPOR5L2DGjs.consentRefusedError; exports.defaultRegistry = _chunk72XZWQX7js.defaultRegistry; exports.deriveHeaders = _chunk72XZWQX7js.deriveHeaders; exports.dispatch = _chunkIXVQ62NZjs.dispatch; exports.exitClasses = _chunkPOR5L2DGjs.exitClasses; exports.exitCodeForClass = _chunkPOR5L2DGjs.exitCodeForClass; exports.genericError = _chunkPOR5L2DGjs.genericError; exports.jsonFormatter = _chunk72XZWQX7js.jsonFormatter; exports.newRegistry = _chunk72XZWQX7js.newRegistry; exports.notFoundError = _chunkPOR5L2DGjs.notFoundError; exports.optionTypeName = _chunk72XZWQX7js.optionTypeName; exports.parseOptions = _chunk72XZWQX7js.parseOptions; exports.prerequisiteError = _chunkPOR5L2DGjs.prerequisiteError; exports.projectRows = _chunk72XZWQX7js.projectRows; exports.provenanceMissingError = _chunkPOR5L2DGjs.provenanceMissingError; exports.rateLimitedError = _chunkPOR5L2DGjs.rateLimitedError; exports.registerOutputFlags = _chunk72XZWQX7js.registerOutputFlags; exports.registryFor = _chunk72XZWQX7js.registryFor; exports.render = _chunkIXVQ62NZjs.render; exports.renderError = _chunkPOR5L2DGjs.renderError; exports.resolveCols = _chunk72XZWQX7js.resolveCols; exports.resolveEffectiveCols = _chunk72XZWQX7js.resolveEffectiveCols; exports.tableFormatter = _chunk72XZWQX7js.tableFormatter; exports.transienceForCode = _chunkPOR5L2DGjs.transienceForCode; exports.transientError = _chunkPOR5L2DGjs.transientError; exports.unauthorizedError = _chunkPOR5L2DGjs.unauthorizedError; exports.unwrapError = _chunkPOR5L2DGjs.unwrapError; exports.usageError = _chunkPOR5L2DGjs.usageError; exports.withTransience = _chunkPOR5L2DGjs.withTransience; exports.wrapError = _chunkPOR5L2DGjs.wrapError; exports.yamlFormatter = _chunk72XZWQX7js.yamlFormatter;
|
package/package.json
CHANGED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { CommanderError } from 'commander';
|
|
3
|
+
import { createCLI, setCommandGroup } from './cli';
|
|
4
|
+
|
|
5
|
+
// "help <operand...>" resolution, matching the Go root's order:
|
|
6
|
+
// "all", then a fully-resolved command path, then a group ID, else a
|
|
7
|
+
// usage error (exit 2). A command wins over a group of the same name.
|
|
8
|
+
|
|
9
|
+
const ANSI = /\x1b\[[0-9;]*m/g;
|
|
10
|
+
|
|
11
|
+
interface Run { out: string; err: string; code: number }
|
|
12
|
+
|
|
13
|
+
function makeCLI() {
|
|
14
|
+
const { program } = createCLI({
|
|
15
|
+
name: 'prog', version: '1.0.0', description: 'root desc',
|
|
16
|
+
groups: [
|
|
17
|
+
{ id: 'management', title: 'MANAGEMENT', hidden: true },
|
|
18
|
+
{ id: 'extras', title: 'EXTRAS' },
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
let out = '';
|
|
22
|
+
let err = '';
|
|
23
|
+
program.exitOverride();
|
|
24
|
+
program.configureOutput({
|
|
25
|
+
writeOut: (s: string) => { out += s; },
|
|
26
|
+
writeErr: (s: string) => { err += s; },
|
|
27
|
+
});
|
|
28
|
+
program.command('map').alias('mp').description('Map things')
|
|
29
|
+
.option('--deep', 'Map recursively');
|
|
30
|
+
const remote = program.command('remote').description('Manage remotes');
|
|
31
|
+
remote.command('add').description('Add a remote')
|
|
32
|
+
.option('--fetch', 'Fetch after adding');
|
|
33
|
+
setCommandGroup(program.command('config').description('Manage config'), 'management');
|
|
34
|
+
// Command sharing its name with a group ID.
|
|
35
|
+
program.command('extras').description('Extras command');
|
|
36
|
+
return {
|
|
37
|
+
program,
|
|
38
|
+
run(args: string[]): Run {
|
|
39
|
+
let code = -1;
|
|
40
|
+
// Group help is signalled through process.argv; keep it local.
|
|
41
|
+
const argv = process.argv;
|
|
42
|
+
process.argv = [...argv];
|
|
43
|
+
try {
|
|
44
|
+
program.parse(args, { from: 'user' });
|
|
45
|
+
code = 0;
|
|
46
|
+
} catch (e) {
|
|
47
|
+
if (!(e instanceof CommanderError)) throw e;
|
|
48
|
+
code = e.exitCode;
|
|
49
|
+
} finally {
|
|
50
|
+
process.argv = argv;
|
|
51
|
+
}
|
|
52
|
+
return { out: out.replace(ANSI, ''), err: err.replace(ANSI, ''), code };
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
describe('help <command> subcommand', () => {
|
|
58
|
+
it('help <command> prints that command\'s help, not root help', () => {
|
|
59
|
+
const r = makeCLI().run(['help', 'map']);
|
|
60
|
+
expect(r.code).toBe(0);
|
|
61
|
+
expect(r.out).toContain('Usage: prog map');
|
|
62
|
+
expect(r.out).toContain('--deep');
|
|
63
|
+
expect(r.out).not.toContain('COMMANDS:');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('help <alias> resolves to the aliased command', () => {
|
|
67
|
+
const r = makeCLI().run(['help', 'mp']);
|
|
68
|
+
expect(r.code).toBe(0);
|
|
69
|
+
expect(r.out).toContain('Usage: prog map');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('help <a> <b> prints nested command help', () => {
|
|
73
|
+
const r = makeCLI().run(['help', 'remote', 'add']);
|
|
74
|
+
expect(r.code).toBe(0);
|
|
75
|
+
expect(r.out).toContain('Usage: prog remote add');
|
|
76
|
+
expect(r.out).toContain('--fetch');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('help <group> still prints group help', () => {
|
|
80
|
+
const r = makeCLI().run(['help', 'management']);
|
|
81
|
+
expect(r.code).toBe(0);
|
|
82
|
+
expect(r.out).toContain('MANAGEMENT:');
|
|
83
|
+
expect(r.out).toContain('config');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('command wins over a group of the same name', () => {
|
|
87
|
+
const r = makeCLI().run(['help', 'extras']);
|
|
88
|
+
expect(r.code).toBe(0);
|
|
89
|
+
expect(r.out).toContain('Usage: prog extras');
|
|
90
|
+
expect(r.out).not.toContain('EXTRAS:');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('unknown topic is a usage error (exit 2)', () => {
|
|
94
|
+
const r = makeCLI().run(['help', 'nosuch']);
|
|
95
|
+
expect(r.code).toBe(2);
|
|
96
|
+
expect(r.err).toContain('unknown help topic \'nosuch\'');
|
|
97
|
+
expect(r.out).not.toContain('Usage: prog');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('partial path is a usage error, not parent help', () => {
|
|
101
|
+
const r = makeCLI().run(['help', 'remote', 'nosuch']);
|
|
102
|
+
expect(r.code).toBe(2);
|
|
103
|
+
expect(r.err).toContain('unknown help topic \'remote nosuch\'');
|
|
104
|
+
});
|
|
105
|
+
});
|
package/src/cli.test.ts
CHANGED
|
@@ -247,6 +247,45 @@ describe('help structure — line-by-line parity', () => {
|
|
|
247
247
|
});
|
|
248
248
|
});
|
|
249
249
|
|
|
250
|
+
describe('help ARGUMENTS section', () => {
|
|
251
|
+
/** Plain help lines for a `gen` command with the given arguments. */
|
|
252
|
+
function genHelpLines(withDescriptions: boolean): string[] {
|
|
253
|
+
const { program } = createCLI({ name: 'mytool', version: '1.2.3', description: 'A tool' });
|
|
254
|
+
const gen = program.command('gen').description('Generate');
|
|
255
|
+
if (withDescriptions) {
|
|
256
|
+
gen.argument('<shell>', 'shell to generate for')
|
|
257
|
+
.argument('[out]', 'output path');
|
|
258
|
+
} else {
|
|
259
|
+
gen.argument('<shell>').argument('[out]');
|
|
260
|
+
}
|
|
261
|
+
gen.option('--force', 'overwrite');
|
|
262
|
+
return stripANSI(gen.helpInformation()).split('\n');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
it('lists described arguments with their descriptions', () => {
|
|
266
|
+
const lines = genHelpLines(true);
|
|
267
|
+
const argIdx = lines.findIndex(l => l.trim() === 'ARGUMENTS:');
|
|
268
|
+
expect(argIdx).toBeGreaterThanOrEqual(0);
|
|
269
|
+
expect(lines[argIdx + 1]).toMatch(/^\s+shell\s+shell to generate for$/);
|
|
270
|
+
expect(lines[argIdx + 2]).toMatch(/^\s+out\s+output path$/);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('ARGUMENTS: appears after the description and before FLAGS:', () => {
|
|
274
|
+
const lines = genHelpLines(true);
|
|
275
|
+
const descIdx = lines.findIndex(l => l.trim() === 'Generate');
|
|
276
|
+
const argIdx = lines.findIndex(l => l.trim() === 'ARGUMENTS:');
|
|
277
|
+
const flagIdx = lines.findIndex(l => l.trim() === 'FLAGS:');
|
|
278
|
+
expect(descIdx).toBeLessThan(argIdx);
|
|
279
|
+
expect(argIdx).toBeLessThan(flagIdx);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('omits ARGUMENTS: when no argument has a description', () => {
|
|
283
|
+
const lines = genHelpLines(false);
|
|
284
|
+
expect(lines.some(l => l.trim() === 'ARGUMENTS:')).toBe(false);
|
|
285
|
+
expect(lines.some(l => l.trim() === 'Arguments:')).toBe(false);
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
250
289
|
describe('CLIConfig disable', () => {
|
|
251
290
|
it('disable.format=true → no format key in opts after parse', () => {
|
|
252
291
|
const { program } = createCLI({
|
package/src/cli.ts
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
import { Command, Help } from 'commander';
|
|
29
29
|
import { parity, type ParityData } from './tui/parity.js';
|
|
30
30
|
import { registerOutputFlags } from './output/flags.js';
|
|
31
|
+
import { EXIT_USAGE } from './output/error.js';
|
|
31
32
|
import { install as installNetPolicy, setProcessOffline } from './netpolicy.js';
|
|
32
33
|
import './output/builtins.js';
|
|
33
34
|
export { ErrOffline, OfflineError, guardFetch, isOffline, isOfflineError,
|
|
@@ -556,6 +557,21 @@ export function applyHelpTheme(
|
|
|
556
557
|
output.push('');
|
|
557
558
|
}
|
|
558
559
|
|
|
560
|
+
// Arguments — only listed when at least one carries a description
|
|
561
|
+
// (Commander's visibleArguments rule); title from parity.json.
|
|
562
|
+
const argList = helper.visibleArguments(cmd);
|
|
563
|
+
if (argList.length > 0) {
|
|
564
|
+
const title = parity.help.sections?.['arguments']?.title ?? 'ARGUMENTS';
|
|
565
|
+
output.push(helper.styleTitle(`${title}:`));
|
|
566
|
+
for (const a of argList) {
|
|
567
|
+
output.push(callFormatItem(
|
|
568
|
+
helper.styleArgumentTerm(helper.argumentTerm(a)),
|
|
569
|
+
helper.styleArgumentDescription(helper.argumentDescription(a)),
|
|
570
|
+
));
|
|
571
|
+
}
|
|
572
|
+
output.push('');
|
|
573
|
+
}
|
|
574
|
+
|
|
559
575
|
// Collect sections in parity order.
|
|
560
576
|
const helpSections: { name: string; items: string[] }[] = [];
|
|
561
577
|
|
|
@@ -691,6 +707,22 @@ export function applyHelpTheme(
|
|
|
691
707
|
});
|
|
692
708
|
}
|
|
693
709
|
|
|
710
|
+
/**
|
|
711
|
+
* Resolves operands as a command path below root, matching names and
|
|
712
|
+
* aliases. Only a fully-resolved path counts: "remote nosuch" names no
|
|
713
|
+
* command rather than falling back to "remote".
|
|
714
|
+
*/
|
|
715
|
+
function findHelpTarget(root: Command, operands: string[]): Command | undefined {
|
|
716
|
+
let cmd: Command | undefined;
|
|
717
|
+
let scope = root;
|
|
718
|
+
for (const word of operands) {
|
|
719
|
+
cmd = scope.commands.find(c => c.name() === word || c.aliases().includes(word));
|
|
720
|
+
if (!cmd) return undefined;
|
|
721
|
+
scope = cmd;
|
|
722
|
+
}
|
|
723
|
+
return cmd;
|
|
724
|
+
}
|
|
725
|
+
|
|
694
726
|
// ---------------------------------------------------------------------------
|
|
695
727
|
// Factory
|
|
696
728
|
// ---------------------------------------------------------------------------
|
|
@@ -810,21 +842,34 @@ export function createCLI(cfg: CLIConfig): CLIResult {
|
|
|
810
842
|
});
|
|
811
843
|
}
|
|
812
844
|
|
|
813
|
-
// help
|
|
845
|
+
// help [command | group] subcommand (hidden from default help).
|
|
846
|
+
// Operands resolve in order: "all", a fully-resolved command path
|
|
847
|
+
// (a command wins over a group of the same name), a group ID; else a
|
|
848
|
+
// usage error (exit 2).
|
|
814
849
|
if (cfg.groups && cfg.groups.length > 0) {
|
|
815
850
|
const groupIds = cfg.groups.map(g => g.id);
|
|
816
|
-
const helpCmd = program.command('help [
|
|
817
|
-
.description('Show help for a command group')
|
|
818
|
-
.action((
|
|
819
|
-
if (
|
|
820
|
-
process.argv.push('--help-all');
|
|
851
|
+
const helpCmd = program.command('help [operands...]')
|
|
852
|
+
.description('Show help for a command or command group')
|
|
853
|
+
.action((operands: string[]) => {
|
|
854
|
+
if (operands.length === 0) {
|
|
821
855
|
program.help();
|
|
822
|
-
}
|
|
823
|
-
|
|
856
|
+
}
|
|
857
|
+
if (operands.length === 1 && operands[0] === 'all') {
|
|
858
|
+
process.argv.push('--help-all');
|
|
824
859
|
program.help();
|
|
825
|
-
}
|
|
860
|
+
}
|
|
861
|
+
const target = findHelpTarget(program, operands);
|
|
862
|
+
if (target) {
|
|
863
|
+
target.help();
|
|
864
|
+
}
|
|
865
|
+
if (operands.length === 1 && groupIds.includes(operands[0]!)) {
|
|
866
|
+
process.argv.push(`--help-${operands[0]}`);
|
|
826
867
|
program.help();
|
|
827
868
|
}
|
|
869
|
+
program.error(
|
|
870
|
+
`error: unknown help topic '${operands.join(' ')}' for '${program.name()}'`,
|
|
871
|
+
{ exitCode: EXIT_USAGE, code: 'commander.unknownCommand' },
|
|
872
|
+
);
|
|
828
873
|
});
|
|
829
874
|
// Hide from default help output.
|
|
830
875
|
(helpCmd as any).hideHelp = true;
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
var _chunk72XZWQX7js = require('./chunk-72XZWQX7.js');
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
|
|
@@ -41,7 +42,6 @@
|
|
|
41
42
|
|
|
42
43
|
|
|
43
44
|
|
|
44
|
-
var _chunkPOR5L2DGjs = require('./chunk-POR5L2DG.js');
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
|
|
@@ -59,7 +59,7 @@ var _chunkPOR5L2DGjs = require('./chunk-POR5L2DG.js');
|
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
|
|
62
|
-
var
|
|
62
|
+
var _chunkPOR5L2DGjs = require('./chunk-POR5L2DG.js');
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|