@silvery/commander 0.18.2 → 0.19.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/package.json +19 -15
- package/dist/index.d.mts +0 -719
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -582
- package/dist/index.mjs.map +0 -1
- package/dist/plain.d.mts +0 -3
- package/dist/plain.mjs +0 -3
- package/dist/presets-DGCyXjnC.mjs +0 -141
- package/dist/presets-DGCyXjnC.mjs.map +0 -1
- package/dist/presets-DTzPdB8a.d.mts +0 -89
- package/dist/presets-DTzPdB8a.d.mts.map +0 -1
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/command.ts","../src/colorize.ts","../src/z.ts"],"mappings":";;;;;;;;;;;;UAyDU,iBAAA;EAAA,SACC,WAAA;IAAA,SACE,OAAA;IAAA,SACA,MAAA;IAAA,SACA,QAAA,GAAW,KAAA,cAAmB,IAAA;IAAA,SAC9B,KAAA;MAAA,SAAmB,MAAA;IAAA;EAAA;AAAA;;KAK3B,YAAA,WAAuB,iBAAA,IAAqB,WAAA,CAAY,CAAA;;;;;;;;;;;KAgBxD,eAAA,qBAAoC,CAAA,sCACrC,IAAA,qCACE,IAAA,GACA,IAAA,GACF,CAAA,wCACE,IAAA,qCACE,IAAA,GACA,IAAA,GACF,CAAA,yBACE,CAAA;;;;;;;;KAUH,SAAA,qBAA8B,CAAA,mDAC5B,CAAA,GAAI,SAAA,CAAU,CAAA,IAAK,SAAA,CAAU,IAAA,MAChC,CAAA;;AAAC;;;;;;;;KAeA,cAAA,qBAAmC,CAAA,gCACpC,IAAA,GACA,CAAA,6BACE,IAAA,GACA,CAAA,gCACE,IAAA,GACA,CAAA,6BACE,IAAA;;KAIL,aAAA,qBAAkC,CAAA;;KAGlC,aAAA,qBAAkC,CAAA;;;;;KAMlC,MAAA,qBAA2B,SAAA,CAAU,cAAA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CAAA,CAAA,IAAA,CAAA,SAAA,MAAA,OAAA,CAAA,GAAA,CAAA,kBAAA,CAAA,GAAA,CAAA,CAAA,CAAA,IAAA,CAAA,KAAA,CAAA,CAAA;iGAA0L,GAAA,CAAA,CAAA,CAAA,IAAA,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,CAAA,IAAA,CAAA,SAAA,MAAA,OAAA,CAAA,GAAA,CAAA,kBAAA,CAAA,GAAA,CAAA,CAAA,CAAA,IAAA,CAAA,MAAA,CAAA,CAAA"}
|
package/dist/index.mjs
DELETED
|
@@ -1,582 +0,0 @@
|
|
|
1
|
-
import { a as float, c as json, d as regex, f as uint, i as email, l as path, n as csv, o as int, p as url, r as date, s as intRange, t as bool, u as port } from "./presets-DGCyXjnC.mjs";
|
|
2
|
-
import { Argument, Command as Command$1, CommanderError, Help, Help as Help$1, InvalidArgumentError, Option, Option as Option$1 } from "commander";
|
|
3
|
-
import { createStyle } from "@silvery/ansi";
|
|
4
|
-
import * as zod from "zod";
|
|
5
|
-
//#region src/colorize.ts
|
|
6
|
-
/**
|
|
7
|
-
* Commander.js help colorization using @silvery/ansi.
|
|
8
|
-
*
|
|
9
|
-
* Uses Commander's built-in style hooks (styleTitle, styleOptionText, etc.)
|
|
10
|
-
* rather than regex post-processing.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { Command } from "@silvery/commander"
|
|
15
|
-
* // Command auto-colorizes in its constructor — no manual call needed.
|
|
16
|
-
* // For plain Commander:
|
|
17
|
-
* import { colorizeHelp } from "@silvery/commander"
|
|
18
|
-
* colorizeHelp(program)
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
const autoStyle = createStyle();
|
|
22
|
-
const s = createStyle({ level: "basic" });
|
|
23
|
-
/**
|
|
24
|
-
* Check if color output should be enabled.
|
|
25
|
-
* Delegates to @silvery/ansi's auto-detection (NO_COLOR, FORCE_COLOR, TERM).
|
|
26
|
-
*/
|
|
27
|
-
function shouldColorize() {
|
|
28
|
-
return autoStyle.level > 0;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Apply colorized help output to a Commander.js program and all its subcommands.
|
|
32
|
-
*
|
|
33
|
-
* Uses Commander's built-in `configureHelp()` style hooks rather than
|
|
34
|
-
* post-processing the formatted string.
|
|
35
|
-
*
|
|
36
|
-
* @param program - A Commander Command instance (or compatible object)
|
|
37
|
-
* @param options - Override default style functions for each element
|
|
38
|
-
*/
|
|
39
|
-
function colorizeHelp(program, options) {
|
|
40
|
-
const cmds = options?.commands ?? ((t) => s.primary(t));
|
|
41
|
-
const flags = options?.flags ?? ((t) => s.secondary(t));
|
|
42
|
-
const desc = options?.description ?? ((t) => t);
|
|
43
|
-
const heading = options?.heading ?? ((t) => s.bold(t));
|
|
44
|
-
const brackets = options?.brackets ?? ((t) => s.accent(t));
|
|
45
|
-
program.configureHelp({
|
|
46
|
-
styleTitle: (str) => heading(str),
|
|
47
|
-
styleCommandText: (str) => cmds(str),
|
|
48
|
-
styleOptionText: (str) => flags(str),
|
|
49
|
-
styleSubcommandText: (str) => cmds(str),
|
|
50
|
-
styleArgumentText: (str) => brackets(str),
|
|
51
|
-
styleDescriptionText: (str) => desc(str),
|
|
52
|
-
styleCommandDescription: (str) => s.bold.primary(str)
|
|
53
|
-
});
|
|
54
|
-
program.configureOutput({
|
|
55
|
-
getOutHasColors: () => true,
|
|
56
|
-
getErrHasColors: () => true
|
|
57
|
-
});
|
|
58
|
-
for (const sub of program.commands) colorizeHelp(sub, options);
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/tokenize.ts
|
|
62
|
-
/** Detect a shell prompt at the start of a line. Supports `$ `, `# `, `> `, `❯ `. */
|
|
63
|
-
const PROMPT_RE = /^([$#>❯]\s+)/;
|
|
64
|
-
/** Match one of: long/short flag, bracket arg, quoted string, bare token, whitespace. */
|
|
65
|
-
const TOKEN_RE = /(--?\S+)|(<[^>]+>|\[[^\]]+\])|('[^']*'|"[^"]*")|(\S+)|(\s+)/g;
|
|
66
|
-
/** Bare command-word pattern (letters/digits/dash, no dots or slashes). */
|
|
67
|
-
const BARE_WORD_RE = /^[a-z][\w-]*$/i;
|
|
68
|
-
/**
|
|
69
|
-
* Tokenize a single line of shell-like text.
|
|
70
|
-
*
|
|
71
|
-
* Classification (matches the original styleSectionTerm contract):
|
|
72
|
-
* - First non-whitespace bare word after the prompt is `program`.
|
|
73
|
-
* - The IMMEDIATELY-FOLLOWING bare word (the second bare word) is `subcommand`,
|
|
74
|
-
* IF it looks like a command word (lowercase letter start, no dots/slashes).
|
|
75
|
-
* - All subsequent bare words are `value`s (filenames, package names, etc.).
|
|
76
|
-
* - Flags (`--foo`, `-f`), bracket args (`<x>`, `[y]`), and quoted strings end
|
|
77
|
-
* the "command portion" — anything after them is a value.
|
|
78
|
-
*
|
|
79
|
-
* The "max 1 subcommand" rule keeps `$ npm install foo` correctly classified
|
|
80
|
-
* as program/subcommand/value (not program/subcommand/subcommand). For nested
|
|
81
|
-
* commands (`$ git remote add ...`), only the first subcommand level is styled.
|
|
82
|
-
*
|
|
83
|
-
* If the line has no shell prompt, the same classification still applies —
|
|
84
|
-
* the leading word is `program`, etc.
|
|
85
|
-
*/
|
|
86
|
-
function tokenizeCmdline(line) {
|
|
87
|
-
const tokens = [];
|
|
88
|
-
const promptMatch = line.match(PROMPT_RE);
|
|
89
|
-
let body = line;
|
|
90
|
-
if (promptMatch) {
|
|
91
|
-
tokens.push({
|
|
92
|
-
kind: "prompt",
|
|
93
|
-
text: promptMatch[1]
|
|
94
|
-
});
|
|
95
|
-
body = line.slice(promptMatch[1].length);
|
|
96
|
-
}
|
|
97
|
-
const matches = body.match(TOKEN_RE) ?? [];
|
|
98
|
-
let commandWords = 0;
|
|
99
|
-
let doneWithCommand = false;
|
|
100
|
-
for (const token of matches) {
|
|
101
|
-
if (/^\s+$/.test(token)) {
|
|
102
|
-
tokens.push({
|
|
103
|
-
kind: "whitespace",
|
|
104
|
-
text: token
|
|
105
|
-
});
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
if (/^--?\S/.test(token)) {
|
|
109
|
-
doneWithCommand = true;
|
|
110
|
-
tokens.push({
|
|
111
|
-
kind: "flag",
|
|
112
|
-
text: token
|
|
113
|
-
});
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
if (/^[<[]/.test(token)) {
|
|
117
|
-
doneWithCommand = true;
|
|
118
|
-
tokens.push({
|
|
119
|
-
kind: "arg-bracket",
|
|
120
|
-
text: token
|
|
121
|
-
});
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
if (/^["']/.test(token)) {
|
|
125
|
-
doneWithCommand = true;
|
|
126
|
-
tokens.push({
|
|
127
|
-
kind: "quoted",
|
|
128
|
-
text: token
|
|
129
|
-
});
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
if (!doneWithCommand && commandWords === 0) {
|
|
133
|
-
commandWords++;
|
|
134
|
-
tokens.push({
|
|
135
|
-
kind: "program",
|
|
136
|
-
text: token
|
|
137
|
-
});
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
if (!doneWithCommand && commandWords === 1 && BARE_WORD_RE.test(token)) {
|
|
141
|
-
commandWords++;
|
|
142
|
-
tokens.push({
|
|
143
|
-
kind: "subcommand",
|
|
144
|
-
text: token
|
|
145
|
-
});
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
doneWithCommand = true;
|
|
149
|
-
tokens.push({
|
|
150
|
-
kind: "value",
|
|
151
|
-
text: token
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
return tokens;
|
|
155
|
-
}
|
|
156
|
-
/** Returns true if the line starts with a recognized shell prompt. */
|
|
157
|
-
function isShellLine(line) {
|
|
158
|
-
return PROMPT_RE.test(line);
|
|
159
|
-
}
|
|
160
|
-
//#endregion
|
|
161
|
-
//#region src/command.ts
|
|
162
|
-
/**
|
|
163
|
-
* Enhanced Commander Command with auto-colorized help, Standard Schema support,
|
|
164
|
-
* array-as-choices detection, and **type-safe option + argument inference**.
|
|
165
|
-
*
|
|
166
|
-
* Subclasses Commander's Command so `new Command("app")` just works --
|
|
167
|
-
* it's Commander with auto-colorized help, automatic Standard Schema /
|
|
168
|
-
* legacy Zod detection, and array choices in `.option()` and `.argument()`.
|
|
169
|
-
*
|
|
170
|
-
* Each `.option()` call narrows the return type so that `.action()`, `.opts()`,
|
|
171
|
-
* and `.actionMerged()` know exactly which options exist and what types they have.
|
|
172
|
-
* Each `.argument()` call appends to both a positional tuple (for `.action()`)
|
|
173
|
-
* and a named record (for `.actionMerged()`).
|
|
174
|
-
*
|
|
175
|
-
* `.action(fn)` is Commander-native: positional args, then options, then command.
|
|
176
|
-
* `.actionMerged(fn)` is an opt-in helper that merges args and options into a
|
|
177
|
-
* single named object — nicer for commands with many positional arguments.
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* ```ts
|
|
181
|
-
* import { Command, port, csv } from "@silvery/commander"
|
|
182
|
-
*
|
|
183
|
-
* // Commander-native: positional args, then options
|
|
184
|
-
* new Command("deploy")
|
|
185
|
-
* .argument("<service>", "Service to deploy")
|
|
186
|
-
* .argument("[env]", "Environment", ["dev", "staging", "prod"])
|
|
187
|
-
* .option("-p, --port <n>", "Port", port)
|
|
188
|
-
* .option("--verbose", "Verbose output")
|
|
189
|
-
* .action((service, env, opts) => {
|
|
190
|
-
* service // string
|
|
191
|
-
* env // "dev" | "staging" | "prod" | undefined
|
|
192
|
-
* opts.port // number | undefined
|
|
193
|
-
* opts.verbose // boolean | undefined
|
|
194
|
-
* })
|
|
195
|
-
*
|
|
196
|
-
* // Merged form: flat named object with args and options merged
|
|
197
|
-
* new Command("deploy")
|
|
198
|
-
* .argument("<service>")
|
|
199
|
-
* .argument("[env]", ["dev", "staging", "prod"] as const)
|
|
200
|
-
* .option("-p, --port <n>", "Port", port)
|
|
201
|
-
* .actionMerged(({ service, env, port }) => { ... })
|
|
202
|
-
*
|
|
203
|
-
* program.parse()
|
|
204
|
-
* ```
|
|
205
|
-
*/
|
|
206
|
-
/** Runtime check: is this value a Standard Schema v1 object? */
|
|
207
|
-
function isStandardSchema(value) {
|
|
208
|
-
return typeof value === "object" && value !== null && "~standard" in value;
|
|
209
|
-
}
|
|
210
|
-
/** Wrap a Standard Schema as a Commander parser function */
|
|
211
|
-
function standardSchemaParser(schema) {
|
|
212
|
-
return (value) => {
|
|
213
|
-
const result = schema["~standard"].validate(value);
|
|
214
|
-
if ("issues" in result) {
|
|
215
|
-
const msg = result.issues.map((i) => i.message).join(", ");
|
|
216
|
-
throw new Error(msg);
|
|
217
|
-
}
|
|
218
|
-
return result.value;
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
function isLegacyZodSchema(value) {
|
|
222
|
-
return typeof value === "object" && value !== null && typeof value.parse === "function" && "_def" in value && !("~standard" in value);
|
|
223
|
-
}
|
|
224
|
-
function legacyZodParser(schema) {
|
|
225
|
-
return (value) => {
|
|
226
|
-
try {
|
|
227
|
-
return schema.parse(value);
|
|
228
|
-
} catch (err) {
|
|
229
|
-
if (err?.issues) {
|
|
230
|
-
const messages = err.issues.map((i) => i.message).join(", ");
|
|
231
|
-
throw new Error(messages);
|
|
232
|
-
}
|
|
233
|
-
throw err;
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Style a SINGLE-LINE section term using Commander's style hooks.
|
|
239
|
-
*
|
|
240
|
-
* Three modes:
|
|
241
|
-
* - Shell command line (`$ termless play demo.tape`): tokenize via tokenizeCmdline()
|
|
242
|
-
* and style each token by kind (dim prompt, primary program/subcommand,
|
|
243
|
-
* secondary flags, accent brackets, dim quoted strings, plain values)
|
|
244
|
-
* - Option-like (`-f, --flag`): entire term styled as option
|
|
245
|
-
* - Plain text: command words + argument brackets
|
|
246
|
-
*
|
|
247
|
-
* For multi-line terms, callers split on \n and call this per line — see
|
|
248
|
-
* _renderSections().
|
|
249
|
-
*/
|
|
250
|
-
function styleSectionTerm(term, helper) {
|
|
251
|
-
if (isShellLine(term)) return styleCmdlineTokens(tokenizeCmdline(term), helper);
|
|
252
|
-
if (/^\s*-/.test(term)) return helper.styleOptionText(term);
|
|
253
|
-
const parts = term.split(/(<[^>]+>|\[[^\]]+\])/g);
|
|
254
|
-
if (parts.length === 1) return helper.styleCommandText(term);
|
|
255
|
-
return parts.map((part) => {
|
|
256
|
-
if (/^[<[]/.test(part)) return helper.styleArgumentText(part);
|
|
257
|
-
if (part) return helper.styleCommandText(part);
|
|
258
|
-
return part;
|
|
259
|
-
}).join("");
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Apply style hooks to a stream of CmdlineTokens.
|
|
263
|
-
*
|
|
264
|
-
* Each token kind maps to one of Commander's style hooks (or a manual ANSI
|
|
265
|
-
* dim escape for prompts/quoted strings, since Commander's style hook set
|
|
266
|
-
* doesn't have a "dim" entry).
|
|
267
|
-
*/
|
|
268
|
-
function styleCmdlineTokens(tokens, helper) {
|
|
269
|
-
const dim = (text) => shouldColorize() ? `\x1b[2m${text}\x1b[22m` : text;
|
|
270
|
-
return tokens.map((t) => {
|
|
271
|
-
switch (t.kind) {
|
|
272
|
-
case "prompt": return dim(t.text);
|
|
273
|
-
case "program":
|
|
274
|
-
case "subcommand": return helper.styleCommandText(t.text);
|
|
275
|
-
case "flag": return helper.styleOptionText(t.text);
|
|
276
|
-
case "arg-bracket": return helper.styleArgumentText(t.text);
|
|
277
|
-
case "quoted": return dim(t.text);
|
|
278
|
-
case "value":
|
|
279
|
-
case "whitespace": return t.text;
|
|
280
|
-
}
|
|
281
|
-
}).join("");
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Compute the longest visual width of any line within a (possibly multi-line) term.
|
|
285
|
-
* Used for column alignment when terms span multiple lines.
|
|
286
|
-
*/
|
|
287
|
-
function maxLineWidth(term) {
|
|
288
|
-
let max = 0;
|
|
289
|
-
for (const line of term.split("\n")) if (line.length > max) max = line.length;
|
|
290
|
-
return max;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Type-safe Commander Command with auto-colorized help, Standard Schema support,
|
|
294
|
-
* array-as-choices detection, and inferred option types.
|
|
295
|
-
*
|
|
296
|
-
* Use `.action()` for Commander-native positional form — `(arg1, arg2, opts, cmd) => ...`.
|
|
297
|
-
* Use `.actionMerged()` for a flat destructured form — `({ arg1, arg2, opt1 }, cmd) => ...`.
|
|
298
|
-
*
|
|
299
|
-
* @example
|
|
300
|
-
* ```ts
|
|
301
|
-
* new Command("deploy")
|
|
302
|
-
* .argument("<service>", "Service to deploy")
|
|
303
|
-
* .argument("[env]", "Environment", ["dev", "staging", "prod"] as const)
|
|
304
|
-
* .option("--verbose", "Verbose output")
|
|
305
|
-
* .action((service, env, opts) => { ... })
|
|
306
|
-
* // or: .actionMerged(({ service, env, verbose }) => { ... })
|
|
307
|
-
* ```
|
|
308
|
-
*/
|
|
309
|
-
const Command = class _CommandBase extends Command$1 {
|
|
310
|
-
_helpSectionList = [];
|
|
311
|
-
_helpSectionsInstalled = false;
|
|
312
|
-
/** Argument names registered via typed .argument() — used by .action() to merge into opts. */
|
|
313
|
-
_typedArgNames = [];
|
|
314
|
-
constructor(name) {
|
|
315
|
-
super(name);
|
|
316
|
-
colorizeHelp(this);
|
|
317
|
-
this._capitalizeBuiltinDescriptions();
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Add an option with smart third-argument detection.
|
|
321
|
-
*
|
|
322
|
-
* The third argument is detected in order:
|
|
323
|
-
* 1. **Array** -- treated as choices (Commander `.choices()`)
|
|
324
|
-
* 2. **Standard Schema v1** -- wrapped as a parser function
|
|
325
|
-
* 3. **Legacy Zod** (pre-3.24, has `_def` + `parse`) -- wrapped as a parser
|
|
326
|
-
* 4. **Function** -- passed through as Commander's parser function
|
|
327
|
-
* 5. **Anything else** -- passed through as a default value
|
|
328
|
-
*/
|
|
329
|
-
option(flags, description, parseArgOrDefault, defaultValue) {
|
|
330
|
-
if (Array.isArray(parseArgOrDefault)) {
|
|
331
|
-
const opt = new Option$1(flags, description ?? "").choices(parseArgOrDefault);
|
|
332
|
-
this.addOption(opt);
|
|
333
|
-
return this;
|
|
334
|
-
}
|
|
335
|
-
if (isStandardSchema(parseArgOrDefault)) return super.option(flags, description ?? "", standardSchemaParser(parseArgOrDefault), defaultValue);
|
|
336
|
-
if (isLegacyZodSchema(parseArgOrDefault)) return super.option(flags, description ?? "", legacyZodParser(parseArgOrDefault), defaultValue);
|
|
337
|
-
if (typeof parseArgOrDefault === "function") return super.option(flags, description ?? "", parseArgOrDefault, defaultValue);
|
|
338
|
-
return super.option(flags, description ?? "", parseArgOrDefault);
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* Add an argument with smart third-argument detection.
|
|
342
|
-
*
|
|
343
|
-
* Same detection as `.option()`: array → choices, Standard Schema → parser,
|
|
344
|
-
* legacy Zod → parser, function → parser, anything else → default value.
|
|
345
|
-
* Tracks argument names for `.action()` merging.
|
|
346
|
-
*/
|
|
347
|
-
argument(flags, description, parseArgOrDefault, defaultValue) {
|
|
348
|
-
const camelName = flags.replace(/[<\[\]>.]/g, "").trim().replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
349
|
-
this._typedArgNames.push(camelName);
|
|
350
|
-
if (Array.isArray(parseArgOrDefault)) {
|
|
351
|
-
const arg = this.createArgument(flags, description ?? "");
|
|
352
|
-
arg.choices(parseArgOrDefault);
|
|
353
|
-
this.addArgument(arg);
|
|
354
|
-
return this;
|
|
355
|
-
}
|
|
356
|
-
if (isStandardSchema(parseArgOrDefault)) return super.argument(flags, description ?? "", standardSchemaParser(parseArgOrDefault), defaultValue);
|
|
357
|
-
if (isLegacyZodSchema(parseArgOrDefault)) return super.argument(flags, description ?? "", legacyZodParser(parseArgOrDefault), defaultValue);
|
|
358
|
-
if (typeof parseArgOrDefault === "function") return super.argument(flags, description ?? "", parseArgOrDefault, defaultValue);
|
|
359
|
-
return super.argument(flags, description ?? "", parseArgOrDefault);
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Register an action callback with a named-parameter object instead of positional args.
|
|
363
|
-
*
|
|
364
|
-
* The handler receives a single object containing all positional arguments
|
|
365
|
-
* (merged by name) and all options, plus the Command instance as a second arg.
|
|
366
|
-
* Argument names come from the typed `.argument()` calls, camelCased.
|
|
367
|
-
*
|
|
368
|
-
* This is a convenience wrapper over `.action()` — `.action()` itself remains
|
|
369
|
-
* Commander-native `(...args, opts, command) => ...`. Prefer `.action()` for
|
|
370
|
-
* single-arg commands (where positional is more ergonomic) and `.actionMerged()`
|
|
371
|
-
* for multi-arg commands (where a flat named object is nicer).
|
|
372
|
-
*
|
|
373
|
-
* @example
|
|
374
|
-
* ```ts
|
|
375
|
-
* new Command("deploy")
|
|
376
|
-
* .argument("<service>")
|
|
377
|
-
* .argument("[env]")
|
|
378
|
-
* .option("-p, --port <n>", port)
|
|
379
|
-
* .actionMerged(({ service, env, port }, cmd) => {
|
|
380
|
-
* // service, env, port are all typed
|
|
381
|
-
* // cmd is the Command instance
|
|
382
|
-
* })
|
|
383
|
-
* ```
|
|
384
|
-
*/
|
|
385
|
-
actionMerged(fn) {
|
|
386
|
-
const argNames = this._typedArgNames;
|
|
387
|
-
return super.action((...args) => {
|
|
388
|
-
const cmd = args[args.length - 1];
|
|
389
|
-
const merged = { ...args[args.length - 2] ?? {} };
|
|
390
|
-
for (let i = 0; i < argNames.length; i++) merged[argNames[i]] = args[i];
|
|
391
|
-
return fn(merged, cmd);
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
addHelpSection(positionOrTitle, titleOrContent, content) {
|
|
395
|
-
let position;
|
|
396
|
-
let title;
|
|
397
|
-
let body;
|
|
398
|
-
if (content !== void 0) {
|
|
399
|
-
position = positionOrTitle;
|
|
400
|
-
title = titleOrContent;
|
|
401
|
-
body = content;
|
|
402
|
-
} else {
|
|
403
|
-
position = "after";
|
|
404
|
-
title = positionOrTitle;
|
|
405
|
-
body = titleOrContent;
|
|
406
|
-
}
|
|
407
|
-
this._helpSectionList.push({
|
|
408
|
-
position,
|
|
409
|
-
title,
|
|
410
|
-
content: body
|
|
411
|
-
});
|
|
412
|
-
this._installHelpSectionHooks();
|
|
413
|
-
return this;
|
|
414
|
-
}
|
|
415
|
-
createCommand(name) {
|
|
416
|
-
return new _CommandBase(name);
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Override Commander's `command()` to mirror inline-arg names (from
|
|
420
|
-
* `command("deploy <service>")`) into our `_typedArgNames`. This keeps
|
|
421
|
-
* `.actionMerged()` working on subcommands declared with the inline form,
|
|
422
|
-
* since the merged dispatch reads from `_typedArgNames` to know which
|
|
423
|
-
* positional indices map to which key.
|
|
424
|
-
*
|
|
425
|
-
* Both forms now coexist:
|
|
426
|
-
* .command("deploy <service>") // inline — names from string
|
|
427
|
-
* .command("deploy").argument("<service>") // explicit — names from .argument()
|
|
428
|
-
* Both produce equivalent runtime + type behavior.
|
|
429
|
-
*/
|
|
430
|
-
command(...args) {
|
|
431
|
-
const result = super.command.apply(this, args);
|
|
432
|
-
const sub = this.commands[this.commands.length - 1];
|
|
433
|
-
if (sub && Array.isArray(sub._args)) for (const arg of sub._args) {
|
|
434
|
-
const camel = arg.name().replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
435
|
-
if (!sub._typedArgNames.includes(camel)) sub._typedArgNames.push(camel);
|
|
436
|
-
}
|
|
437
|
-
return result;
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Auto-detect capitalization from user-provided descriptions and match it
|
|
441
|
-
* for built-in options (-V/--version, -h/--help).
|
|
442
|
-
*/
|
|
443
|
-
_capitalizeBuiltinDescriptions() {
|
|
444
|
-
const origHelp = this.helpInformation.bind(this);
|
|
445
|
-
this.helpInformation = () => {
|
|
446
|
-
const builtinFlags = new Set(["-V, --version", "-h, --help"]);
|
|
447
|
-
const userDescs = this.options.filter((opt) => !builtinFlags.has(opt.flags) && opt.description && /^[a-zA-Z]/.test(opt.description)).map((opt) => opt.description);
|
|
448
|
-
for (const cmd of this.commands) if (cmd.description() && /^[a-zA-Z]/.test(cmd.description())) userDescs.push(cmd.description());
|
|
449
|
-
if (userDescs.length > 0) {
|
|
450
|
-
if (userDescs.filter((d) => /^[A-Z]/.test(d)).length > userDescs.length / 2) {
|
|
451
|
-
for (const opt of this.options) if (builtinFlags.has(opt.flags) && opt.description && /^[a-z]/.test(opt.description)) opt.description = opt.description[0].toUpperCase() + opt.description.slice(1);
|
|
452
|
-
const helpOpt = this._helpOption;
|
|
453
|
-
if (helpOpt?.description && /^[a-z]/.test(helpOpt.description)) helpOpt.description = helpOpt.description[0].toUpperCase() + helpOpt.description.slice(1);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
return origHelp();
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Render sections for a given position using the help formatter.
|
|
461
|
-
*
|
|
462
|
-
* Handles multi-line term entries (terms containing `\n`) by emitting one
|
|
463
|
-
* row per line. The description column is **top-aligned**: it appears only
|
|
464
|
-
* on the first line of a multi-line term, with subsequent lines holding
|
|
465
|
-
* just the styled term and an empty description column.
|
|
466
|
-
*/
|
|
467
|
-
_renderSections(position, helper, termWidth) {
|
|
468
|
-
const sections = this._helpSectionList.filter((s) => s.position === position);
|
|
469
|
-
if (sections.length === 0) return "";
|
|
470
|
-
const lines = [];
|
|
471
|
-
for (const section of sections) {
|
|
472
|
-
lines.push("");
|
|
473
|
-
lines.push(helper.styleTitle(section.title));
|
|
474
|
-
if (typeof section.content === "string") for (const line of section.content.split("\n")) lines.push(` ${line}`);
|
|
475
|
-
else for (const [term, desc] of section.content) {
|
|
476
|
-
const termLines = term.split("\n");
|
|
477
|
-
for (let i = 0; i < termLines.length; i++) {
|
|
478
|
-
const lineText = termLines[i];
|
|
479
|
-
const styledTerm = styleSectionTerm(lineText, helper);
|
|
480
|
-
const lineDesc = i === 0 ? helper.styleDescriptionText(desc) : "";
|
|
481
|
-
lines.push(helper.formatItem(styledTerm, termWidth, lineDesc, helper));
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
lines.push("");
|
|
486
|
-
return lines.join("\n");
|
|
487
|
-
}
|
|
488
|
-
/** Install hooks once — merges with existing configureHelp, adds addHelpText for before/afterAll. */
|
|
489
|
-
_installHelpSectionHooks() {
|
|
490
|
-
if (this._helpSectionsInstalled) return;
|
|
491
|
-
this._helpSectionsInstalled = true;
|
|
492
|
-
const self = this;
|
|
493
|
-
const existing = this._helpConfiguration ?? {};
|
|
494
|
-
const origPadWidth = existing.padWidth;
|
|
495
|
-
const origFormatHelp = existing.formatHelp;
|
|
496
|
-
const protoFormatHelp = Help$1.prototype.formatHelp;
|
|
497
|
-
this.configureHelp({
|
|
498
|
-
...existing,
|
|
499
|
-
padWidth(cmd, helper) {
|
|
500
|
-
const base = origPadWidth ? origPadWidth(cmd, helper) : Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength?.(cmd, helper) ?? 0, helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
501
|
-
if (cmd !== self) return base;
|
|
502
|
-
let sectionMax = 0;
|
|
503
|
-
for (const section of self._helpSectionList) if (typeof section.content !== "string") for (const [term] of section.content) {
|
|
504
|
-
const w = maxLineWidth(term);
|
|
505
|
-
if (w > sectionMax) sectionMax = w;
|
|
506
|
-
}
|
|
507
|
-
return Math.max(base, sectionMax);
|
|
508
|
-
},
|
|
509
|
-
formatHelp(cmd, helper) {
|
|
510
|
-
const baseHelp = origFormatHelp ? origFormatHelp(cmd, helper) : protoFormatHelp.call(helper, cmd, helper);
|
|
511
|
-
if (cmd !== self) return baseHelp;
|
|
512
|
-
const termWidth = helper.padWidth(cmd, helper);
|
|
513
|
-
const before = self._renderSections("before", helper, termWidth);
|
|
514
|
-
const after = self._renderSections("after", helper, termWidth);
|
|
515
|
-
return (before ? before + "\n" : "") + baseHelp + after;
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
this.addHelpText("beforeAll", () => {
|
|
519
|
-
const helper = this.createHelp();
|
|
520
|
-
const termWidth = helper.padWidth(this, helper);
|
|
521
|
-
return this._renderSections("beforeAll", helper, termWidth);
|
|
522
|
-
});
|
|
523
|
-
this.addHelpText("afterAll", () => {
|
|
524
|
-
const helper = this.createHelp();
|
|
525
|
-
const termWidth = helper.padWidth(this, helper);
|
|
526
|
-
return this._renderSections("afterAll", helper, termWidth);
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
};
|
|
530
|
-
//#endregion
|
|
531
|
-
//#region src/z.ts
|
|
532
|
-
/**
|
|
533
|
-
* Extended Zod object with CLI types.
|
|
534
|
-
*
|
|
535
|
-
* Spreads all of Zod's exports and adds CLI-specific schemas.
|
|
536
|
-
* Tree-shakeable -- only evaluated if user imports `z`.
|
|
537
|
-
*
|
|
538
|
-
* @example
|
|
539
|
-
* ```ts
|
|
540
|
-
* import { z, Command } from "@silvery/commander"
|
|
541
|
-
*
|
|
542
|
-
* new Command("deploy")
|
|
543
|
-
* .option("-p, --port <n>", "Port", z.port)
|
|
544
|
-
* .option("--tags <t>", "Tags", z.csv)
|
|
545
|
-
* .option("-e, --env <e>", "Env", ["dev", "staging", "prod"])
|
|
546
|
-
*
|
|
547
|
-
* program.parse()
|
|
548
|
-
* ```
|
|
549
|
-
*/
|
|
550
|
-
const z = {
|
|
551
|
-
...zod,
|
|
552
|
-
port: zod.coerce.number().int().min(1).max(65535),
|
|
553
|
-
int: zod.coerce.number().int(),
|
|
554
|
-
uint: zod.coerce.number().int().min(0),
|
|
555
|
-
float: zod.coerce.number(),
|
|
556
|
-
csv: zod.string().transform((v) => v.split(",").map((s) => s.trim()).filter(Boolean)),
|
|
557
|
-
url: zod.string().url(),
|
|
558
|
-
path: zod.string().min(1),
|
|
559
|
-
email: zod.string().email(),
|
|
560
|
-
date: zod.coerce.date(),
|
|
561
|
-
json: zod.string().transform((v) => JSON.parse(v)),
|
|
562
|
-
bool: zod.enum([
|
|
563
|
-
"true",
|
|
564
|
-
"false",
|
|
565
|
-
"1",
|
|
566
|
-
"0",
|
|
567
|
-
"yes",
|
|
568
|
-
"no",
|
|
569
|
-
"y",
|
|
570
|
-
"n"
|
|
571
|
-
]).transform((v) => [
|
|
572
|
-
"true",
|
|
573
|
-
"1",
|
|
574
|
-
"yes",
|
|
575
|
-
"y"
|
|
576
|
-
].includes(v)),
|
|
577
|
-
intRange: (min, max) => zod.coerce.number().int().min(min).max(max)
|
|
578
|
-
};
|
|
579
|
-
//#endregion
|
|
580
|
-
export { Argument, Command, CommanderError, Help, InvalidArgumentError, Option, bool, colorizeHelp, csv, date, email, float, int, intRange, json, path, port, regex, shouldColorize, uint, url, z };
|
|
581
|
-
|
|
582
|
-
//# sourceMappingURL=index.mjs.map
|