@sdxc/cli 2026.10.24 → 2026.11.10
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 +3 -0
- package/dist/describe.js +4 -1
- package/dist/help.d.ts +9 -0
- package/dist/help.js +17 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/parse.js +1 -1
- package/dist/tree.js +3 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -141,6 +141,8 @@ Every token after the command's name, unparsed, to hand to another program.
|
|
|
141
141
|
command({ arguments: { args: argument.rest() } }); // prog run users --help → ["users", "--help"]
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
+
A program with no commands can declare it on `commands({ arguments: { args: argument.rest() } })` and map a handler to the program itself, so it reads its whole command line, `--help` included.
|
|
145
|
+
|
|
144
146
|
#### `flag.boolean(name, options?)`
|
|
145
147
|
|
|
146
148
|
`--name`, and `--no-name` to turn it off.
|
|
@@ -226,6 +228,7 @@ Runs a command without a terminal and answers `{ code, stdout, stderr, exec }`.
|
|
|
226
228
|
|
|
227
229
|
- `spawnExec`: the default `exec`, over `node:child_process`.
|
|
228
230
|
- `createStyle(enabled)`: the colours `ctx.style` uses, for output outside a handler.
|
|
231
|
+
- `closest(input, candidates)`: the candidate a mistyped name most likely meant, or `undefined`, as the "did you mean" hints for commands and flags pick it.
|
|
229
232
|
- Types: `CommandMiddleware<Effect>` (a middleware publishing `Effect`'s `property`), `Task`, `RunIO`, `Exec`, `ExecOptions`, `ExecOutput`, `HandlerContext`, `ChainContext` (the context a helper shared by several commands takes), `ArgumentsOf`, `FlagsOf`.
|
|
230
233
|
|
|
231
234
|
## Patterns
|
package/dist/describe.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
8
8
|
*/
|
|
9
9
|
import { groupSpec, isGroup } from "./command.js";
|
|
10
|
+
import { exampleLine } from "./help.js";
|
|
10
11
|
/**
|
|
11
12
|
* Describes `entry` and every visible member under it. Hidden commands and flags stay out, as
|
|
12
13
|
* they do from the help.
|
|
@@ -43,7 +44,9 @@ export function describeEntry(entry, program) {
|
|
|
43
44
|
...(spec.hasDefault ? { default: spec.default } : {}),
|
|
44
45
|
})),
|
|
45
46
|
flags,
|
|
46
|
-
examples: isGroup(node)
|
|
47
|
+
examples: isGroup(node)
|
|
48
|
+
? []
|
|
49
|
+
: node.examples.map((example) => exampleLine(programName, example)),
|
|
47
50
|
commands,
|
|
48
51
|
};
|
|
49
52
|
}
|
package/dist/help.d.ts
CHANGED
|
@@ -16,3 +16,12 @@ export interface HelpProgram {
|
|
|
16
16
|
}
|
|
17
17
|
/** Renders `entry`'s help, ending with a newline. */
|
|
18
18
|
export declare function renderHelp(entry: Entry, program: HelpProgram, style: Style): string;
|
|
19
|
+
/**
|
|
20
|
+
* An example as a shell user types it. The program goes before the command after the last
|
|
21
|
+
* pipe, so `cat a.json | hash` reads `cat a.json | prog hash`, and an example that already names
|
|
22
|
+
* the program there is printed as written.
|
|
23
|
+
*
|
|
24
|
+
* @example exampleLine("prog", "hash a.json") // "prog hash a.json"
|
|
25
|
+
* @example exampleLine("prog", "cat a.json | hash") // "cat a.json | prog hash"
|
|
26
|
+
*/
|
|
27
|
+
export declare function exampleLine(program: string, example: string): string;
|
package/dist/help.js
CHANGED
|
@@ -69,11 +69,27 @@ export function renderHelp(entry, program, style) {
|
|
|
69
69
|
sections.push(section(`${heading}:`, rows, style));
|
|
70
70
|
if (!isGroup(node) && node.examples.length > 0) {
|
|
71
71
|
let program = entry.title.split(" ")[0];
|
|
72
|
-
let lines = node.examples.map((example) => ` ${program
|
|
72
|
+
let lines = node.examples.map((example) => ` ${exampleLine(program, example)}`);
|
|
73
73
|
sections.push(`${style.bold("Examples:")}\n${lines.join("\n")}`);
|
|
74
74
|
}
|
|
75
75
|
return `${sections.join("\n\n")}\n`;
|
|
76
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* An example as a shell user types it. The program goes before the command after the last
|
|
79
|
+
* pipe, so `cat a.json | hash` reads `cat a.json | prog hash`, and an example that already names
|
|
80
|
+
* the program there is printed as written.
|
|
81
|
+
*
|
|
82
|
+
* @example exampleLine("prog", "hash a.json") // "prog hash a.json"
|
|
83
|
+
* @example exampleLine("prog", "cat a.json | hash") // "cat a.json | prog hash"
|
|
84
|
+
*/
|
|
85
|
+
export function exampleLine(program, example) {
|
|
86
|
+
let pipe = example.lastIndexOf("| ");
|
|
87
|
+
let before = pipe === -1 ? "" : example.slice(0, pipe + 2);
|
|
88
|
+
let command = pipe === -1 ? example : example.slice(pipe + 2);
|
|
89
|
+
if (command === program || command.startsWith(`${program} `))
|
|
90
|
+
return example;
|
|
91
|
+
return `${before}${program} ${command}`;
|
|
92
|
+
}
|
|
77
93
|
/** A titled section of aligned rows, flag and command names styled. */
|
|
78
94
|
function section(title, rows, style) {
|
|
79
95
|
let width = Math.max(0, ...rows.map(([left]) => visibleWidth(left)));
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export { CancelledError, EXIT_CODES, ExitError, UsageError, cancelled, exit, exi
|
|
|
30
30
|
export { ExecError, spawnExec } from "./exec.js";
|
|
31
31
|
export { flag } from "./flag.js";
|
|
32
32
|
export { createCommand } from "./handler.js";
|
|
33
|
+
export { closest } from "./suggest.js";
|
|
33
34
|
export { lazy } from "./lazy.js";
|
|
34
35
|
export { prompt } from "./prompt.js";
|
|
35
36
|
export { createStyle } from "./style.js";
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export { CancelledError, EXIT_CODES, ExitError, UsageError, cancelled, exit, exi
|
|
|
14
14
|
export { ExecError, spawnExec } from "./exec.js";
|
|
15
15
|
export { flag } from "./flag.js";
|
|
16
16
|
export { createCommand } from "./handler.js";
|
|
17
|
+
export { closest } from "./suggest.js";
|
|
17
18
|
export { lazy } from "./lazy.js";
|
|
18
19
|
export { prompt } from "./prompt.js";
|
|
19
20
|
export { createStyle } from "./style.js";
|
package/dist/parse.js
CHANGED
|
@@ -30,7 +30,7 @@ export function parseArgv(tree, argv, withVersion) {
|
|
|
30
30
|
issues: [],
|
|
31
31
|
};
|
|
32
32
|
let index = 0;
|
|
33
|
-
let rest =
|
|
33
|
+
let rest = tree.root.rest;
|
|
34
34
|
/** Flag tokens read at a group, replayed against the member the command line goes on to name. */
|
|
35
35
|
let atGroup = [];
|
|
36
36
|
/** How many issues stood before the current group's flags were read. */
|
package/dist/tree.js
CHANGED
|
@@ -67,8 +67,9 @@ export function buildTree(name, root) {
|
|
|
67
67
|
args.push({ key, spec });
|
|
68
68
|
});
|
|
69
69
|
let rest = args.some((arg) => arg.spec.rest);
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
let nested = isGroup(node) && (path.length > 0 || Object.keys(groupSpec(node).members).length > 0);
|
|
71
|
+
if (rest && (nested || flags.length > 0 || args.length !== 1)) {
|
|
72
|
+
throw new Error(`${title}: argument.rest() is the only argument of a command, or of a program with no commands, with no flags`);
|
|
72
73
|
}
|
|
73
74
|
let entry = {
|
|
74
75
|
node,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdxc/cli",
|
|
3
|
-
"version": "2026.10
|
|
3
|
+
"version": "2026.11.10",
|
|
4
4
|
"description": "Build command-line tools with generated help, prompts bound to flags, tasks and a test harness",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
"@standard-schema/spec": "^1.1.0"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"remix": "3.
|
|
17
|
+
"remix": "3.2.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependenciesMeta": {
|
|
20
20
|
"remix": {
|
|
21
21
|
"optional": true
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "6191b60a13885b1d826884d574c4a393f9b8eeee",
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"access": "public"
|
|
27
27
|
},
|