politty 0.7.0 → 0.9.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.
Files changed (63) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/docs/index.d.ts +44 -2
  3. package/dist/docs/index.js +827 -43
  4. package/dist/index.js +1 -1
  5. package/dist/{runner-D43SkHt5.js → runner-APRZYXUS.js} +74 -3
  6. package/package.json +22 -67
  7. package/dist/arg-registry-DDJpsUea.d.cts +0 -942
  8. package/dist/arg-registry-DDJpsUea.d.cts.map +0 -1
  9. package/dist/arg-registry-DDJpsUea.d.ts.map +0 -1
  10. package/dist/augment.cjs +0 -0
  11. package/dist/augment.d.cts +0 -17
  12. package/dist/augment.d.cts.map +0 -1
  13. package/dist/augment.d.ts.map +0 -1
  14. package/dist/cli.cjs +0 -54
  15. package/dist/cli.cjs.map +0 -1
  16. package/dist/cli.d.cts +0 -1
  17. package/dist/cli.js.map +0 -1
  18. package/dist/completion/index.cjs +0 -23
  19. package/dist/completion/index.d.cts +0 -3
  20. package/dist/completion-CLHO3Xaz.cjs +0 -5769
  21. package/dist/completion-CLHO3Xaz.cjs.map +0 -1
  22. package/dist/completion-DHnVx9Zk.js.map +0 -1
  23. package/dist/docs/index.cjs +0 -2343
  24. package/dist/docs/index.cjs.map +0 -1
  25. package/dist/docs/index.d.cts +0 -710
  26. package/dist/docs/index.d.cts.map +0 -1
  27. package/dist/docs/index.d.ts.map +0 -1
  28. package/dist/docs/index.js.map +0 -1
  29. package/dist/index-DKGn3lIl.d.ts.map +0 -1
  30. package/dist/index-WyViqW59.d.cts +0 -663
  31. package/dist/index-WyViqW59.d.cts.map +0 -1
  32. package/dist/index.cjs +0 -45
  33. package/dist/index.d.cts +0 -685
  34. package/dist/index.d.cts.map +0 -1
  35. package/dist/index.d.ts.map +0 -1
  36. package/dist/log-collector-DK32-73m.js.map +0 -1
  37. package/dist/log-collector-DUqC427m.cjs +0 -185
  38. package/dist/log-collector-DUqC427m.cjs.map +0 -1
  39. package/dist/prompt/clack/index.cjs +0 -33
  40. package/dist/prompt/clack/index.cjs.map +0 -1
  41. package/dist/prompt/clack/index.d.cts +0 -18
  42. package/dist/prompt/clack/index.d.cts.map +0 -1
  43. package/dist/prompt/clack/index.d.ts.map +0 -1
  44. package/dist/prompt/clack/index.js.map +0 -1
  45. package/dist/prompt/index.cjs +0 -7
  46. package/dist/prompt/index.d.cts +0 -108
  47. package/dist/prompt/index.d.cts.map +0 -1
  48. package/dist/prompt/index.d.ts.map +0 -1
  49. package/dist/prompt/inquirer/index.cjs +0 -48
  50. package/dist/prompt/inquirer/index.cjs.map +0 -1
  51. package/dist/prompt/inquirer/index.d.cts +0 -18
  52. package/dist/prompt/inquirer/index.d.cts.map +0 -1
  53. package/dist/prompt/inquirer/index.d.ts.map +0 -1
  54. package/dist/prompt/inquirer/index.js.map +0 -1
  55. package/dist/prompt-Bs9e-Em3.cjs +0 -196
  56. package/dist/prompt-Bs9e-Em3.cjs.map +0 -1
  57. package/dist/prompt-Cc8Tfmdv.js.map +0 -1
  58. package/dist/runner-D43SkHt5.js.map +0 -1
  59. package/dist/runner-DvFvokV6.cjs +0 -2865
  60. package/dist/runner-DvFvokV6.cjs.map +0 -1
  61. package/dist/schema-extractor-BxSRwLrx.cjs +0 -710
  62. package/dist/schema-extractor-BxSRwLrx.cjs.map +0 -1
  63. package/dist/schema-extractor-Dqe7_kyQ.js.map +0 -1
package/dist/index.d.cts DELETED
@@ -1,685 +0,0 @@
1
- import { $ as toKebabCase, A as LogStream, B as SetupContext, C as Example, D as IsEmpty, E as GlobalSetupContext, F as RunCommandOptions, G as isLazyCommand, H as SubCommandsRecord, I as RunResult, J as ResolvedFieldMeta, K as lazy, L as RunResultFailure, M as MainOptions, N as NonRunnableCommand, O as LogEntry, P as PromptResolver, Q as toCamelCase, R as RunResultSuccess, S as CommandBase, T as GlobalCleanupContext, U as UnknownSubcommandHandler, V as SubCommandValue, W as LazyCommand, X as extractFields, Y as UnknownKeysMode, Z as getUnknownKeysMode, _ as AnyCommand, a as EffectContext, b as CollectedLogs, c as arg, d as ResolvedExpandCandidate, f as CompletionDirectiveMask, g as DynamicCompletionResult, h as DynamicCompletionResolver, i as CustomCompletion, j as Logger, k as LogLevel, l as ExpandCandidate, m as DynamicCompletionContext, n as CompletionMeta, o as PromptMeta, p as DynamicCompletionCandidate, q as ExtractedFields, r as CompletionType, s as PromptType, t as ArgMeta, u as ExpandCompletion, v as ArgsSchema, w as GlobalArgs, x as Command, y as CleanupContext, z as RunnableCommand } from "./arg-registry-DDJpsUea.cjs";
2
- import { I as CompletionOptions, L as CompletionResult, c as withCompletionCommand, d as GenerateBundledCompletionWorkerOptions, f as GenerateBundledCompletionWorkerResult, h as generateBundledCompletionWorker, o as generateCompletion, t as WithCompletionOptions } from "./index-WyViqW59.cjs";
3
- import { z } from "zod";
4
-
5
- //#region src/core/case-types.d.ts
6
- /**
7
- * TypeScript utility types for case conversion between camelCase and kebab-case.
8
- *
9
- * These types enable dual-case access on CLI args objects,
10
- * so that both `args.myOption` and `args["my-option"]` are valid.
11
- */
12
- /**
13
- * Convert a kebab-case string to camelCase at the type level.
14
- *
15
- * @example
16
- * type R = CamelCase<"my-option">; // "myOption"
17
- * type R2 = CamelCase<"already">; // "already"
18
- */
19
- type CamelCase<S extends string> = S extends `${infer P}-${infer C}${infer R}` ? `${P}${Uppercase<C>}${CamelCase<R>}` : S;
20
- /**
21
- * Internal helper: insert hyphens before uppercase-to-lowercase transitions.
22
- * Matches the runtime `toKebabCase()` behavior:
23
- * - `([a-z])([A-Z])` → insert hyphen (e.g. "myOption" → "my-Option")
24
- * - `([A-Z]+)([A-Z][a-z])` → insert hyphen before last capital in a run
25
- * (e.g. "XMLParser" → "XML-Parser" → "xml-parser")
26
- *
27
- * Note: TypeScript template literal types have limited ability to match
28
- * multi-character uppercase runs precisely. This implementation handles
29
- * common CLI naming patterns (camelCase, PascalCase). For exotic acronym
30
- * patterns (e.g. "XMLParser"), the type-level result may differ slightly
31
- * from the runtime result. Dual-case proxy handles runtime resolution.
32
- */
33
- type KebabCaseInner<S extends string> = S extends `${infer First}${infer Rest}` ? Rest extends "" ? First extends Lowercase<First> ? First : `-${Lowercase<First>}` : First extends Lowercase<First> ? `${First}${KebabCaseInner<Rest>}` : Rest extends `${infer Next}${infer Tail}` ? Next extends Lowercase<Next> ? `-${Lowercase<First>}${Next}${KebabCaseInner<Tail>}` : `${Lowercase<First>}${KebabCaseInner<Rest>}` : `-${Lowercase<First>}` : S;
34
- /**
35
- * Strip a leading hyphen (produced when the first char is uppercase).
36
- */
37
- type StripLeadingHyphen<S extends string> = S extends `-${infer R}` ? R : S;
38
- /**
39
- * Convert a camelCase string to kebab-case at the type level.
40
- * Aligned with the runtime `toKebabCase()` function in schema-extractor.ts.
41
- *
42
- * @example
43
- * type R = KebabCase<"myOption">; // "my-option"
44
- * type R2 = KebabCase<"already">; // "already"
45
- */
46
- type KebabCase<S extends string> = StripLeadingHyphen<KebabCaseInner<S>>;
47
- /**
48
- * Add both camelCase and kebab-case variants for every key in T.
49
- *
50
- * Given `{ "my-option": string }`, produces
51
- * `{ "my-option": string } & { myOption: string }`.
52
- *
53
- * Given `{ myOption: string }`, produces
54
- * `{ myOption: string } & { "my-option": string }`.
55
- *
56
- * Keys that are identical in both cases (e.g. single-word keys) are not duplicated.
57
- * Uses a distributive conditional type so it works correctly with discriminated unions.
58
- */
59
- type WithCaseVariants<T> = T extends unknown ? T & { [K in keyof T as CamelCase<K & string>]: T[K] } & { [K in keyof T as KebabCase<K & string>]: T[K] } : never;
60
- //#endregion
61
- //#region src/core/case-proxy.d.ts
62
- /**
63
- * Wrap an args object with a Proxy that allows dual-case access.
64
- *
65
- * Given `{ "my-option": "value" }`, both `obj["my-option"]` and `obj.myOption`
66
- * will return `"value"`.
67
- *
68
- * - `Object.keys()`, `JSON.stringify()`, and spread return only the original keys.
69
- * - The `in` operator detects both case variants.
70
- */
71
- declare function createDualCaseProxy<T extends Record<string, unknown>>(obj: T): WithCaseVariants<T>;
72
- //#endregion
73
- //#region src/core/command.d.ts
74
- /**
75
- * Infer args type from schema, defaults to empty object if undefined.
76
- * Wraps with WithCaseVariants so both camelCase and kebab-case access is typed.
77
- */
78
- type InferArgs<TArgsSchema> = TArgsSchema extends z.ZodType ? WithCaseVariants<z.infer<TArgsSchema>> : Record<string, never>;
79
- /**
80
- * Merge local args with global args.
81
- * No-op when TGlobalArgs is empty (default GlobalArgs not extended).
82
- * Wraps TGlobalArgs with WithCaseVariants for dual-case access.
83
- */
84
- type MergedArgs<TLocalArgs, TGlobalArgs> = IsEmpty<TGlobalArgs> extends true ? TLocalArgs : TLocalArgs & WithCaseVariants<TGlobalArgs>;
85
- /**
86
- * Resolve merged args from schema and global args type
87
- */
88
- type ResolvedArgs<TArgsSchema, TGlobalArgs> = MergedArgs<InferArgs<TArgsSchema>, TGlobalArgs>;
89
- /**
90
- * Config for defining a command
91
- * @template TArgsSchema - The Zod schema type for arguments
92
- * @template TResult - The return type of run function (void if no run)
93
- * @template TGlobalArgs - Global args type (from declaration merging or factory)
94
- */
95
- interface DefineCommandConfig<TArgsSchema extends ArgsSchema | undefined, TResult, TGlobalArgs> {
96
- name: string;
97
- description?: string;
98
- aliases?: string[];
99
- args?: TArgsSchema;
100
- subCommands?: SubCommandsRecord;
101
- setup?: (context: {
102
- args: ResolvedArgs<TArgsSchema, TGlobalArgs>;
103
- }) => void | Promise<void>;
104
- run?: (args: ResolvedArgs<TArgsSchema, TGlobalArgs>) => TResult;
105
- cleanup?: (context: {
106
- args: ResolvedArgs<TArgsSchema, TGlobalArgs>;
107
- error?: Error | undefined;
108
- }) => void | Promise<void>;
109
- notes?: string;
110
- examples?: Example[];
111
- }
112
- /**
113
- * Config with run function (runnable command)
114
- */
115
- interface RunnableConfig<TArgsSchema extends ArgsSchema | undefined, TResult, TGlobalArgs> extends DefineCommandConfig<TArgsSchema, TResult, TGlobalArgs> {
116
- run: (args: ResolvedArgs<TArgsSchema, TGlobalArgs>) => TResult;
117
- }
118
- /**
119
- * Config without run function (non-runnable command)
120
- */
121
- interface NonRunnableConfig<TArgsSchema extends ArgsSchema | undefined, TGlobalArgs> extends Omit<DefineCommandConfig<TArgsSchema, void, TGlobalArgs>, "run"> {
122
- run?: undefined;
123
- }
124
- /**
125
- * Define a CLI command with type-safe arguments
126
- *
127
- * @param config - Command configuration
128
- * @returns A defined command with preserved type information
129
- *
130
- * @example
131
- * ```ts
132
- * import { z } from "zod";
133
- * import { arg, defineCommand } from "politty";
134
- *
135
- * const command = defineCommand({
136
- * name: "greet",
137
- * args: z.object({
138
- * name: arg(z.string(), { description: "Name to greet", positional: true }),
139
- * loud: arg(z.boolean().default(false), { alias: "l", description: "Use uppercase" }),
140
- * }),
141
- * run: (args) => {
142
- * const greeting = `Hello, ${args.name}!`;
143
- * console.log(args.loud ? greeting.toUpperCase() : greeting);
144
- * },
145
- * });
146
- *
147
- * // Type of command.argsSchema is preserved as z.ZodObject<...>
148
- * // Type of command.run is (args: { name: string; loud: boolean }) => void
149
- * ```
150
- *
151
- * @example
152
- * ```ts
153
- * // With discriminated union for subcommand-like behavior
154
- * const command = defineCommand({
155
- * name: "resource",
156
- * args: z.discriminatedUnion("action", [
157
- * z.object({
158
- * action: z.literal("create"),
159
- * name: arg(z.string(), { description: "Resource name" }),
160
- * }),
161
- * z.object({
162
- * action: z.literal("delete"),
163
- * id: arg(z.coerce.number(), { description: "Resource ID" }),
164
- * }),
165
- * ]),
166
- * run: (args) => {
167
- * if (args.action === "create") {
168
- * console.log(`Creating ${args.name}`);
169
- * } else {
170
- * console.log(`Deleting ${args.id}`);
171
- * }
172
- * },
173
- * });
174
- * ```
175
- */
176
- declare function defineCommand<TArgsSchema extends ArgsSchema | undefined = undefined, TResult = void, TGlobalArgs = GlobalArgs>(config: RunnableConfig<TArgsSchema, TResult, TGlobalArgs>): RunnableCommand<TArgsSchema, ResolvedArgs<TArgsSchema, TGlobalArgs>, TResult>;
177
- declare function defineCommand<TArgsSchema extends ArgsSchema | undefined = undefined, TGlobalArgs = GlobalArgs>(config: NonRunnableConfig<TArgsSchema, TGlobalArgs>): NonRunnableCommand<TArgsSchema, ResolvedArgs<TArgsSchema, TGlobalArgs>>;
178
- /**
179
- * Create a typed defineCommand factory with pre-bound global args type.
180
- * This is the recommended pattern for type-safe global options.
181
- *
182
- * @example
183
- * ```ts
184
- * // global-args.ts
185
- * type GlobalArgsType = { verbose: boolean; config?: string };
186
- * export const defineAppCommand = createDefineCommand<GlobalArgsType>();
187
- *
188
- * // commands/build.ts
189
- * export const buildCommand = defineAppCommand({
190
- * name: "build",
191
- * args: z.object({ output: arg(z.string().default("dist")) }),
192
- * run: (args) => {
193
- * args.verbose; // typed via GlobalArgsType
194
- * args.output; // typed via local args
195
- * },
196
- * });
197
- * ```
198
- */
199
- declare function createDefineCommand<TGlobalArgs>(): {
200
- <TArgsSchema extends ArgsSchema | undefined = undefined, TResult = void>(config: RunnableConfig<TArgsSchema, TResult, TGlobalArgs>): RunnableCommand<TArgsSchema, ResolvedArgs<TArgsSchema, TGlobalArgs>, TResult>;
201
- <TArgsSchema extends ArgsSchema | undefined = undefined>(config: NonRunnableConfig<TArgsSchema, TGlobalArgs>): NonRunnableCommand<TArgsSchema, ResolvedArgs<TArgsSchema, TGlobalArgs>>;
202
- };
203
- //#endregion
204
- //#region src/core/runner.d.ts
205
- /**
206
- * Run a command with the given arguments (programmatic/test usage)
207
- *
208
- * This function parses arguments, validates them, routes to subcommands,
209
- * and executes the command. It does NOT call process.exit.
210
- *
211
- * @param command - The command to run
212
- * @param argv - Command line arguments to parse
213
- * @param options - Run options
214
- * @returns The result of command execution
215
- *
216
- * @example
217
- * ```ts
218
- * import { defineCommand, runCommand } from "politty";
219
- *
220
- * const command = defineCommand({
221
- * name: "my-cli",
222
- * args: z.object({ name: z.string() }),
223
- * run: ({ name }) => console.log(`Hello, ${name}!`),
224
- * });
225
- *
226
- * // In tests
227
- * const result = await runCommand(command, ["--name", "World"]);
228
- * expect(result.exitCode).toBe(0);
229
- * ```
230
- */
231
- declare function runCommand<TResult = unknown>(command: AnyCommand, argv: string[], options?: RunCommandOptions): Promise<RunResult<TResult>>;
232
- /**
233
- * Run a CLI command as the main entry point
234
- *
235
- * This function:
236
- * - Uses process.argv for arguments
237
- * - Handles SIGINT/SIGTERM signals
238
- * - Calls process.exit with the appropriate exit code
239
- * - Invokes `command.runMainHook` once before parsing if set, so plug-ins
240
- * like `withCompletionCommand` can fire detached background work
241
- * - Bypasses user `setup`/`cleanup`/`prompt` and required `globalArgs`
242
- * for registered hidden subcommands whose name starts with `__`
243
- * (e.g. `__refresh-completion`)
244
- *
245
- * @param command - The command to run
246
- * @param options - Main options (version, debug)
247
- *
248
- * @example
249
- * ```ts
250
- * import { defineCommand, runMain } from "politty";
251
- *
252
- * const command = defineCommand({
253
- * name: "my-cli",
254
- * run: () => console.log("Hello!"),
255
- * });
256
- *
257
- * runMain(command, { version: "1.0.0" });
258
- * ```
259
- */
260
- declare function runMain(command: AnyCommand, options?: MainOptions): Promise<never>;
261
- //#endregion
262
- //#region src/output/help-generator.d.ts
263
- /**
264
- * Descriptions for built-in options
265
- */
266
- interface BuiltinOptionDescriptions {
267
- /** Description for --help option */
268
- help?: string;
269
- /** Description for --help-all option */
270
- helpAll?: string;
271
- /** Description for --version option */
272
- version?: string;
273
- }
274
- /**
275
- * Context for command hierarchy
276
- */
277
- interface CommandContext {
278
- /** Full command path (e.g., ["config", "get"]) */
279
- commandPath?: string[] | undefined;
280
- /** Root command name */
281
- rootName?: string | undefined;
282
- /** Root command version */
283
- rootVersion?: string | undefined;
284
- /** Extracted fields from global args schema */
285
- globalExtracted?: ExtractedFields | undefined;
286
- /** When the command was accessed via an alias, the canonical command name */
287
- aliasFor?: string | undefined;
288
- }
289
- /**
290
- * Options for help generation
291
- */
292
- interface HelpOptions {
293
- /** Show subcommand list */
294
- showSubcommands?: boolean | undefined;
295
- /** Show subcommand options */
296
- showSubcommandOptions?: boolean | undefined;
297
- /** Custom descriptions for built-in options */
298
- descriptions?: BuiltinOptionDescriptions | undefined;
299
- /** Command hierarchy context */
300
- context?: CommandContext | undefined;
301
- }
302
- /**
303
- * Generate help text for a command
304
- *
305
- * @param command - The command to generate help for
306
- * @param options - Help generation options
307
- * @returns Formatted help text
308
- */
309
- declare function generateHelp(command: AnyCommand, options: HelpOptions): string;
310
- //#endregion
311
- //#region src/output/logger.d.ts
312
- /**
313
- * Enable or disable color output programmatically
314
- */
315
- declare function setColorEnabled(enabled: boolean): void;
316
- /**
317
- * Check if color output is currently enabled
318
- */
319
- declare function isColorEnabled(): boolean;
320
- /**
321
- * Semantic style functions for inline text styling
322
- */
323
- declare const styles: {
324
- success: (text: string) => string;
325
- error: (text: string) => string;
326
- warning: (text: string) => string;
327
- info: (text: string) => string;
328
- bold: (text: string) => string;
329
- dim: (text: string) => string;
330
- italic: (text: string) => string;
331
- underline: (text: string) => string;
332
- red: (text: string) => string;
333
- green: (text: string) => string;
334
- yellow: (text: string) => string;
335
- blue: (text: string) => string;
336
- magenta: (text: string) => string;
337
- cyan: (text: string) => string;
338
- white: (text: string) => string;
339
- gray: (text: string) => string;
340
- command: (text: string) => string;
341
- commandName: (text: string) => string;
342
- option: (text: string) => string;
343
- optionName: (text: string) => string;
344
- placeholder: (text: string) => string;
345
- defaultValue: (text: string) => string;
346
- required: (text: string) => string;
347
- description: (text: string) => string;
348
- sectionHeader: (text: string) => string;
349
- version: (text: string) => string;
350
- };
351
- /**
352
- * Standardized symbols for CLI output
353
- */
354
- declare const symbols: {
355
- success: string;
356
- error: string;
357
- warning: string;
358
- info: string;
359
- bullet: string;
360
- arrow: string;
361
- };
362
- /**
363
- * Logger for CLI output
364
- */
365
- declare const logger: {
366
- /**
367
- * Log informational message
368
- */
369
- info(message: string): void;
370
- /**
371
- * Log success message
372
- */
373
- success(message: string): void;
374
- /**
375
- * Log warning message
376
- */
377
- warn(message: string): void;
378
- /**
379
- * Log error message
380
- */
381
- error(message: string): void;
382
- /**
383
- * Log raw message without prefix
384
- */
385
- log(message: string): void;
386
- /**
387
- * Log empty line
388
- */
389
- newline(): void;
390
- /**
391
- * Log debug message with dim color
392
- */
393
- debug(message: string): void;
394
- };
395
- //#endregion
396
- //#region src/output/markdown-renderer.d.ts
397
- /**
398
- * Lightweight Markdown-to-terminal renderer.
399
- *
400
- * Supports a subset of Markdown tailored for CLI help notes:
401
- * - Inline: bold, italic, inline code, links
402
- * - Block: paragraphs, unordered/ordered lists, blockquotes, headings,
403
- * horizontal rules, fenced code blocks
404
- */
405
- /**
406
- * Apply inline Markdown formatting to a string.
407
- *
408
- * Processing order matters to avoid conflicts:
409
- * 1. Inline code (backticks) — content inside is literal, no further processing
410
- * 2. Bold (**text**)
411
- * 3. Italic (*text* or _text_)
412
- * 4. Links [text](url)
413
- */
414
- declare function renderInline(text: string): string;
415
- /**
416
- * Render a Markdown string to styled terminal output.
417
- *
418
- * Block-level processing:
419
- * - Splits input into blocks separated by blank lines
420
- * - Detects headings, horizontal rules, blockquotes, lists, code blocks, and paragraphs
421
- * - Applies inline formatting within each block
422
- */
423
- declare function renderMarkdown(markdown: string): string;
424
- //#endregion
425
- //#region src/parser/argv-parser.d.ts
426
- /**
427
- * Parsed arguments result
428
- */
429
- interface ParsedArgv {
430
- /** Named options (--flag, -f) */
431
- options: Record<string, unknown>;
432
- /** Positional arguments */
433
- positionals: string[];
434
- /** Arguments after -- */
435
- rest: string[];
436
- }
437
- /**
438
- * Parser options
439
- */
440
- interface ParserOptions {
441
- /** Alias map (short -> long) */
442
- aliasMap?: Map<string, string>;
443
- /** Boolean flags (no value expected) */
444
- booleanFlags?: Set<string>;
445
- /** Array flags (can be repeated) */
446
- arrayFlags?: Set<string>;
447
- /**
448
- * All known canonical option names (as defined in the schema).
449
- * Used to disambiguate negation: when `--no-flag` or `--noFlag` matches
450
- * a name in this set, it is treated as a regular option rather than
451
- * boolean negation of `flag`.
452
- */
453
- definedNames?: Set<string>;
454
- /**
455
- * Map from a custom negation CLI name (and camelCase variant) to the
456
- * canonical field name. Used to recognize user-defined boolean negation
457
- * options (e.g. `--disable-cache` → `{ cache: false }`).
458
- */
459
- negationMap?: Map<string, string>;
460
- /**
461
- * Canonical field names that have a custom `negation` configured.
462
- * For these fields the default `--no-<name>` / `--no<Name>` negation
463
- * forms are suppressed.
464
- */
465
- customNegatedFields?: Set<string>;
466
- }
467
- /**
468
- * Parse argv into a flat record
469
- *
470
- * Supports:
471
- * - Long options: --flag, --flag=value, --flag value
472
- * - Short options: -f, -f=value, -f value
473
- * - Combined short options: -abc (treated as -a -b -c if all are boolean)
474
- * - Positional arguments
475
- * - -- to stop parsing options
476
- * - Boolean negation: --no-flag, --noFlag (requires `booleanFlags`)
477
- *
478
- * **Note:** When using negation detection (`--noFlag` / `--no-flag`),
479
- * supply `definedNames` so that options whose names happen to start with
480
- * "no" (e.g. `noDryRun`) are not mistaken for negation of another flag.
481
- * Without `definedNames`, all `--noX` forms matching a boolean flag will
482
- * be treated as negation.
483
- *
484
- * @param argv - Command line arguments
485
- * @param options - Parser options
486
- * @returns Parsed arguments
487
- */
488
- declare function parseArgv(argv: string[], options?: ParserOptions): ParsedArgv;
489
- //#endregion
490
- //#region src/validator/validation-errors.d.ts
491
- /**
492
- * Error thrown when positional argument configuration is invalid
493
- */
494
- declare class PositionalConfigError extends Error {
495
- constructor(message: string);
496
- }
497
- /**
498
- * Error thrown when a reserved alias is used
499
- */
500
- declare class ReservedAliasError extends Error {
501
- constructor(message: string);
502
- }
503
- /**
504
- * Error thrown when duplicate field names are detected
505
- */
506
- declare class DuplicateFieldError extends Error {
507
- constructor(message: string);
508
- }
509
- /**
510
- * Error thrown when duplicate aliases are detected
511
- */
512
- declare class DuplicateAliasError extends Error {
513
- constructor(message: string);
514
- }
515
- /**
516
- * Error thrown when fields are case variants of each other (e.g. "my-option" and "myOption")
517
- */
518
- declare class CaseVariantCollisionError extends Error {
519
- constructor(message: string);
520
- }
521
- /**
522
- * Error thrown when a custom boolean negation name collides with another
523
- * field's name, cliName, alias, or another field's negation (including
524
- * derived camelCase variants).
525
- */
526
- declare class DuplicateNegationError extends Error {
527
- constructor(message: string);
528
- }
529
- //#endregion
530
- //#region src/validator/command-validator.d.ts
531
- /**
532
- * Error detail for command validation
533
- */
534
- interface CommandValidationError {
535
- /** Path to the command (e.g., ["cli", "build", "watch"]) */
536
- commandPath: string[];
537
- /** Error type */
538
- type: "duplicate_field" | "duplicate_alias" | "invalid_alias" | "positional_config" | "reserved_alias" | "case_variant_collision" | "duplicate_negation";
539
- /** Error message */
540
- message: string;
541
- /** Related field name (if applicable) */
542
- field?: string;
543
- }
544
- /**
545
- * Result of command validation
546
- */
547
- type CommandValidationResult = {
548
- valid: true;
549
- } | {
550
- valid: false;
551
- errors: CommandValidationError[];
552
- };
553
- /**
554
- * Options for validateCommand
555
- */
556
- interface ValidateCommandOptions {
557
- /** Starting command path (for nested validation) */
558
- commandPath?: string[];
559
- }
560
- /**
561
- * Validate that no duplicate field names exist
562
- *
563
- * @param extracted - Extracted fields from schema
564
- * @throws {DuplicateFieldError} If duplicate field names are found
565
- */
566
- declare function validateDuplicateFields(extracted: ExtractedFields): void;
567
- /**
568
- * Validate that no duplicate aliases exist
569
- *
570
- * Also checks for conflicts between aliases and field names
571
- *
572
- * @param extracted - Extracted fields from schema
573
- * @throws {DuplicateAliasError} If duplicate aliases are found or alias conflicts with field name
574
- */
575
- declare function validateDuplicateAliases(extracted: ExtractedFields): void;
576
- /**
577
- * Validate positional argument configuration
578
- *
579
- * Rules:
580
- * - Array positional arguments must be the last positional
581
- * - No positional arguments can follow an array positional
582
- * - Required positional arguments cannot follow optional positional arguments
583
- * - Array positional and optional positional cannot be used together (ambiguous parsing)
584
- *
585
- * @param extracted - Extracted fields from schema
586
- * @throws {PositionalConfigError} If configuration is invalid
587
- */
588
- declare function validatePositionalConfig(extracted: ExtractedFields): void;
589
- /**
590
- * Validate that no reserved aliases are used without explicit override
591
- *
592
- * Reserved aliases:
593
- * - 'h' is reserved for --help
594
- * - 'H' is reserved for --help-all
595
- *
596
- * Users can override these by setting overrideBuiltinAlias: true
597
- *
598
- * @param extracted - Extracted fields from schema
599
- * @param _hasSubCommands - Whether the command has subcommands (reserved for future use)
600
- * @throws {ReservedAliasError} If a reserved alias is used without override flag
601
- */
602
- declare function validateReservedAliases(extracted: ExtractedFields, _hasSubCommands: boolean): void;
603
- /**
604
- * Validate that custom boolean negation names do not collide with anything
605
- *
606
- * @param extracted - Extracted fields from schema
607
- * @throws {DuplicateNegationError} If a colliding negation is found
608
- */
609
- declare function validateDuplicateNegations(extracted: ExtractedFields): void;
610
- /**
611
- * Validate that no case-variant collisions exist
612
- *
613
- * @param extracted - Extracted fields from schema
614
- * @throws {CaseVariantCollisionError} If case-variant collisions are found
615
- */
616
- declare function validateCaseVariantCollisions(extracted: ExtractedFields): void;
617
- /**
618
- * Validate that no case-variant collisions exist between two schemas
619
- * (e.g., global args and command args).
620
- *
621
- * @param extractedA - Extracted fields from first schema (e.g., global args)
622
- * @param extractedB - Extracted fields from second schema (e.g., command args)
623
- * @throws {CaseVariantCollisionError} If cross-schema case-variant collisions are found
624
- */
625
- declare function validateCrossSchemaCollisions(extractedA: ExtractedFields, extractedB: ExtractedFields): void;
626
- /**
627
- * Validate a command and all its subcommands recursively
628
- *
629
- * This function collects all validation errors without throwing,
630
- * making it suitable for test assertions.
631
- *
632
- * @param command - The command to validate
633
- * @param options - Validation options
634
- * @returns Validation result with all errors collected
635
- *
636
- * @example
637
- * ```ts
638
- * const result = await validateCommand(myCommand);
639
- * if (!result.valid) {
640
- * console.error(result.errors);
641
- * }
642
- * ```
643
- */
644
- declare function validateCommand(command: AnyCommand, options?: ValidateCommandOptions): Promise<CommandValidationResult>;
645
- /**
646
- * Format command validation errors for display
647
- *
648
- * @param errors - Array of validation errors
649
- * @returns Formatted error message
650
- */
651
- declare function formatCommandValidationErrors(errors: CommandValidationError[]): string;
652
- //#endregion
653
- //#region src/validator/zod-validator.d.ts
654
- /**
655
- * Validation error details
656
- */
657
- interface ValidationError {
658
- /** Path to the invalid field */
659
- path: string[];
660
- /** Error message */
661
- message: string;
662
- /** Zod error code */
663
- code: string;
664
- /** Value that was received */
665
- received?: unknown | undefined;
666
- /** Expected type or value */
667
- expected?: string | undefined;
668
- }
669
- /**
670
- * Validation result
671
- */
672
- type ValidationResult<T> = {
673
- success: true;
674
- data: T;
675
- } | {
676
- success: false;
677
- errors: ValidationError[];
678
- };
679
- /**
680
- * Format validation errors for display
681
- */
682
- declare function formatValidationErrors(errors: ValidationError[]): string;
683
- //#endregion
684
- export { type AnyCommand, type ArgMeta, type ArgsSchema, type BuiltinOptionDescriptions, type CamelCase, CaseVariantCollisionError, type CleanupContext, type CollectedLogs, type Command, type CommandBase, type CommandContext, type CommandValidationError, type CommandValidationResult, type CompletionDirectiveMask, type CompletionMeta, type CompletionOptions, type CompletionResult, type CompletionType, type CustomCompletion, DuplicateAliasError, DuplicateFieldError, DuplicateNegationError, type DynamicCompletionCandidate, type DynamicCompletionContext, type DynamicCompletionResolver, type DynamicCompletionResult, type EffectContext, type Example, type ExpandCandidate, type ExpandCompletion, type ExtractedFields, type GenerateBundledCompletionWorkerOptions, type GenerateBundledCompletionWorkerResult, type GlobalArgs, type GlobalCleanupContext, type GlobalSetupContext, type HelpOptions, type KebabCase, type LazyCommand, type LogEntry, type LogLevel, type LogStream, type Logger, type MainOptions, type MergedArgs, type NonRunnableCommand, type ParsedArgv, type ParserOptions, PositionalConfigError, type PromptMeta, type PromptResolver, type PromptType, ReservedAliasError, type ResolvedExpandCandidate, type ResolvedFieldMeta, type RunCommandOptions, type RunResult, type RunResultFailure, type RunResultSuccess, type RunnableCommand, type SetupContext, type SubCommandValue, type SubCommandsRecord, type UnknownKeysMode, type UnknownSubcommandHandler, type ValidationError, type ValidationResult, type WithCaseVariants, type WithCompletionOptions, arg, createDefineCommand, createDualCaseProxy, defineCommand, extractFields, formatCommandValidationErrors, formatValidationErrors, generateBundledCompletionWorker, generateCompletion, generateHelp, getUnknownKeysMode, isColorEnabled, isLazyCommand, lazy, logger, parseArgv, renderInline, renderMarkdown, runCommand, runMain, setColorEnabled, styles, symbols, toCamelCase, toKebabCase, validateCaseVariantCollisions, validateCommand, validateCrossSchemaCollisions, validateDuplicateAliases, validateDuplicateFields, validateDuplicateNegations, validatePositionalConfig, validateReservedAliases, withCompletionCommand };
685
- //# sourceMappingURL=index.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/core/case-types.ts","../src/core/case-proxy.ts","../src/core/command.ts","../src/core/runner.ts","../src/output/help-generator.ts","../src/output/logger.ts","../src/output/markdown-renderer.ts","../src/parser/argv-parser.ts","../src/validator/validation-errors.ts","../src/validator/command-validator.ts","../src/validator/zod-validator.ts"],"mappings":";;;;;;;;;;AAcA;;;;;;;;KAAY,SAAA,qBAA8B,CAAA,gDACnC,CAAA,GAAI,SAAA,CAAU,CAAA,IAAK,SAAA,CAAU,CAAA,MAChC,CAAA;;;;;;;;;;;;;;KAeC,cAAA,qBAAmC,CAAA,yCACpC,IAAA,cACE,KAAA,SAAc,SAAA,CAAU,KAAA,IACtB,KAAA,OACI,SAAA,CAAU,KAAA,MAChB,KAAA,SAAc,SAAA,CAAU,KAAA,OACnB,KAAA,GAAQ,cAAA,CAAe,IAAA,MAC1B,IAAA,wCACE,IAAA,SAAa,SAAA,CAAU,IAAA,QACjB,SAAA,CAAU,KAAA,IAAS,IAAA,GAAO,cAAA,CAAe,IAAA,SAC1C,SAAA,CAAU,KAAA,IAAS,cAAA,CAAe,IAAA,UACnC,SAAA,CAAU,KAAA,MACpB,CAAA;;AA3BC;AAAC;KAgCD,kBAAA,qBAAuC,CAAA,yBAA0B,CAAA,GAAI,CAAC;;;;;;;;;KAU/D,SAAA,qBAA8B,kBAAA,CAAmB,cAAA,CAAe,CAAA;;;;;;;;;;;;;KAchE,gBAAA,MAAsB,CAAA,mBAC9B,CAAA,iBACc,CAAA,IAAK,SAAA,CAAU,CAAA,aAAc,CAAA,CAAE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