@politty/zod 0.0.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/LICENSE +21 -0
- package/README.md +561 -0
- package/bin/cli.mjs +3 -0
- package/dist/arg-registry-YaWTVu_x.d.ts +1025 -0
- package/dist/augment.d.ts +15 -0
- package/dist/augment.js +1 -0
- package/dist/cli-main-Dn88vIyn.js +84 -0
- package/dist/cli-run-eibUcgys.js +7 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +16 -0
- package/dist/command-k-4yAz4J.js +42 -0
- package/dist/compile-cache-Ct41pWGL.js +100 -0
- package/dist/compile-cache.d.ts +78 -0
- package/dist/compile-cache.js +3 -0
- package/dist/completion-gtWX3mwP.js +5608 -0
- package/dist/completion.d.ts +242 -0
- package/dist/completion.js +4 -0
- package/dist/docs.d.ts +770 -0
- package/dist/docs.js +3044 -0
- package/dist/field-meta-DMy5BcRr.js +146 -0
- package/dist/index-CvhsecfS.d.ts +455 -0
- package/dist/index.d.ts +799 -0
- package/dist/index.js +17 -0
- package/dist/log-collector-CoUkLVJB.js +114 -0
- package/dist/logger-i_bb-Jhc.js +133 -0
- package/dist/prompt-CEIZ-7H1.js +171 -0
- package/dist/prompt-clack.d.ts +16 -0
- package/dist/prompt-clack.js +32 -0
- package/dist/prompt-inquirer.d.ts +16 -0
- package/dist/prompt-inquirer.js +47 -0
- package/dist/prompt.d.ts +106 -0
- package/dist/prompt.js +4 -0
- package/dist/register-Bk0K83W2.js +439 -0
- package/dist/runner-D72I7wvK.js +2956 -0
- package/dist/runner-FvUwOHyE.js +3 -0
- package/dist/schema-extractor-DMSozq40.js +250 -0
- package/dist/skill.d.ts +608 -0
- package/dist/skill.js +1832 -0
- package/dist/src-KzC0g5CS.js +191 -0
- package/dist/subcommand-router-Cskpofdk.js +134 -0
- package/package.json +103 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,799 @@
|
|
|
1
|
+
import { $ as toKebabCase, A as LogEntry, B as RunResultSuccess, C as Command, D as GlobalCleanupContext, E as GlobalArgs, F as NonRunnableCommand, G as UnknownSubcommandHandler, H as SetupContext, I as PromptResolver, J as lazy, K as LazyCommand, L as RunCommandOptions, M as LogStream, N as Logger, O as GlobalSetupContext, P as MainOptions, Q as toCamelCase, R as RunResult, S as CollectedLogs, T as Example, U as SubCommandValue, V as RunnableCommand, W as SubCommandsRecord, X as ResolvedFieldMeta, Y as ExtractedFields, Z as UnknownKeysMode, _ as DynamicCompletionResult, a as CustomCompletion, b as ArgsSchema$1, c as PromptType, d as ExpandCompletion, et as InferSchemaOutput, f as ResolvedExpandCandidate, g as DynamicCompletionResolver, h as DynamicCompletionContext, i as CompletionType, j as LogLevel, k as IsEmpty, l as ValidateArgMeta, m as DynamicCompletionCandidate, n as ArgMeta, o as EffectContext, p as CompletionDirectiveMask, q as isLazyCommand, r as CompletionMeta, s as PromptMeta, t as ArgFn, tt as SchemaLike, u as ExpandCandidate, v as AnyCommand, w as CommandBase, x as CleanupContext, y as ArgSource, z as RunResultFailure } from "./arg-registry-YaWTVu_x.js";
|
|
2
|
+
import { C as CompletionResult, D as InternalArgsSchema, S as CompletionOptions, c as withCompletionCommand, l as GenerateBundledCompletionWorkerOptions, o as generateCompletion, p as generateBundledCompletionWorker, t as WithCompletionOptions, u as GenerateBundledCompletionWorkerResult } from "./index-CvhsecfS.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region ../core/src/core/schema-extractor.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Detect the unknown-keys handling mode of an args schema. Works for any
|
|
7
|
+
* schema politty itself attaches to a command (including internal
|
|
8
|
+
* descriptor-based commands), not just user-provided library schemas.
|
|
9
|
+
*/
|
|
10
|
+
declare function getUnknownKeysMode(schema: ArgsSchema$1): UnknownKeysMode;
|
|
11
|
+
/**
|
|
12
|
+
* Extract all fields from a schema
|
|
13
|
+
*
|
|
14
|
+
* @param schema - The args schema (ZodObject, ZodDiscriminatedUnion, etc.)
|
|
15
|
+
* @returns Extracted field information
|
|
16
|
+
*/
|
|
17
|
+
declare function extractFields(schema: ArgsSchema$1): ExtractedFields;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region ../core/src/adapter/types.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* Validation error details
|
|
22
|
+
*/
|
|
23
|
+
interface ValidationError {
|
|
24
|
+
/** Path to the invalid field */
|
|
25
|
+
path: string[];
|
|
26
|
+
/** Error message */
|
|
27
|
+
message: string;
|
|
28
|
+
/** Error code (adapter-specific, e.g. zod issue code) */
|
|
29
|
+
code: string;
|
|
30
|
+
/** Value that was received */
|
|
31
|
+
received?: unknown | undefined;
|
|
32
|
+
/** Expected type or value */
|
|
33
|
+
expected?: string | undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Validation result
|
|
37
|
+
*/
|
|
38
|
+
type ValidationResult<T> = {
|
|
39
|
+
success: true;
|
|
40
|
+
data: T;
|
|
41
|
+
} | {
|
|
42
|
+
success: false;
|
|
43
|
+
errors: ValidationError[];
|
|
44
|
+
};
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region ../core/src/compile-cache-shim.d.ts
|
|
47
|
+
/**
|
|
48
|
+
* Generator for compile-cache bin shims.
|
|
49
|
+
*
|
|
50
|
+
* Emits the minimal entry file described in docs/recipes.md ("Faster
|
|
51
|
+
* Startup"): a shim that enables the Node.js on-disk compile cache via
|
|
52
|
+
* `politty/compile-cache` and then loads the real CLI with a dynamic
|
|
53
|
+
* import. Meant to be wired into a `postbuild` or `prepack` script via
|
|
54
|
+
* `politty generate-shim` so the shim never has to live in source.
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
* Options for {@link generateCompileCacheShim}.
|
|
58
|
+
*/
|
|
59
|
+
interface GenerateCompileCacheShimOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Module specifier(s) the shim imports to start the CLI, relative to the
|
|
62
|
+
* generated shim file (e.g. `./cli.js`). Pass one per shim; when `out` is
|
|
63
|
+
* omitted the count must match the package's `bin` entries (paired in
|
|
64
|
+
* order). Defaults to the first of `./cli.js`, `./cli.mjs`, `./index.js`,
|
|
65
|
+
* `./index.mjs` that exists next to each shim.
|
|
66
|
+
*/
|
|
67
|
+
entry?: string | string[];
|
|
68
|
+
/**
|
|
69
|
+
* Output path(s) for the generated shim(s) (e.g. `dist/bin.js`). When
|
|
70
|
+
* given, the count must match `entry` (paired in order). Defaults to all
|
|
71
|
+
* `bin` paths in the nearest `package.json` — the places the executables
|
|
72
|
+
* must live.
|
|
73
|
+
*/
|
|
74
|
+
out?: string | string[];
|
|
75
|
+
/**
|
|
76
|
+
* Program name used to derive the cache directory, applied to every
|
|
77
|
+
* generated shim. Defaults per shim to the `bin` name whose path is the
|
|
78
|
+
* shim's output, falling back to the first `bin` name and then the
|
|
79
|
+
* package name without its scope. The fallback never happens silently: a
|
|
80
|
+
* warning is printed when an explicit `out` path cannot be matched to a
|
|
81
|
+
* `bin` entry.
|
|
82
|
+
*/
|
|
83
|
+
program?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Base directory for resolving paths and locating the nearest
|
|
86
|
+
* `package.json` (default: `process.cwd()`).
|
|
87
|
+
*/
|
|
88
|
+
cwd?: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* One generated shim from {@link generateCompileCacheShim}.
|
|
92
|
+
*/
|
|
93
|
+
interface GenerateCompileCacheShimResult {
|
|
94
|
+
/** Absolute path of the generated shim. */
|
|
95
|
+
outputPath: string;
|
|
96
|
+
/** Program name baked into the shim. */
|
|
97
|
+
program: string;
|
|
98
|
+
/** Entry specifier baked into the shim. */
|
|
99
|
+
entry: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Generate executable compile-cache bin shims.
|
|
103
|
+
*
|
|
104
|
+
* With no explicit paths, one shim is generated per `bin` entry of the
|
|
105
|
+
* nearest `package.json`, each importing a conventional built module next
|
|
106
|
+
* to it — so a bare `politty generate-shim` in a `postbuild` script is
|
|
107
|
+
* usually enough. Explicit `entry` values are paired in order with the
|
|
108
|
+
* `bin` entries (or with explicit `out` values of the same count).
|
|
109
|
+
*
|
|
110
|
+
* The generated files are ESM (they use top-level `await import`), so `.js`
|
|
111
|
+
* output requires `"type": "module"` in the package; use a `.mjs` extension
|
|
112
|
+
* otherwise. Refuses to overwrite an existing file it did not generate, so
|
|
113
|
+
* a `bin` path still pointing at the real CLI entry fails loudly instead of
|
|
114
|
+
* clobbering the build output.
|
|
115
|
+
*/
|
|
116
|
+
declare function generateCompileCacheShim(options?: GenerateCompileCacheShimOptions): GenerateCompileCacheShimResult[];
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region ../core/src/core/case-types.d.ts
|
|
119
|
+
/**
|
|
120
|
+
* TypeScript utility types for case conversion between camelCase and kebab-case.
|
|
121
|
+
*
|
|
122
|
+
* These types enable dual-case access on CLI args objects,
|
|
123
|
+
* so that both `args.myOption` and `args["my-option"]` are valid.
|
|
124
|
+
*/
|
|
125
|
+
/**
|
|
126
|
+
* Convert a kebab-case string to camelCase at the type level.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* type R = CamelCase<"my-option">; // "myOption"
|
|
130
|
+
* type R2 = CamelCase<"already">; // "already"
|
|
131
|
+
*/
|
|
132
|
+
type CamelCase<S extends string> = S extends `${infer P}-${infer C}${infer R}` ? `${P}${Uppercase<C>}${CamelCase<R>}` : S;
|
|
133
|
+
/**
|
|
134
|
+
* Internal helper: insert hyphens before uppercase-to-lowercase transitions.
|
|
135
|
+
* Matches the runtime `toKebabCase()` behavior:
|
|
136
|
+
* - `([a-z])([A-Z])` → insert hyphen (e.g. "myOption" → "my-Option")
|
|
137
|
+
* - `([A-Z]+)([A-Z][a-z])` → insert hyphen before last capital in a run
|
|
138
|
+
* (e.g. "XMLParser" → "XML-Parser" → "xml-parser")
|
|
139
|
+
*
|
|
140
|
+
* Note: TypeScript template literal types have limited ability to match
|
|
141
|
+
* multi-character uppercase runs precisely. This implementation handles
|
|
142
|
+
* common CLI naming patterns (camelCase, PascalCase). For exotic acronym
|
|
143
|
+
* patterns (e.g. "XMLParser"), the type-level result may differ slightly
|
|
144
|
+
* from the runtime result. Dual-case proxy handles runtime resolution.
|
|
145
|
+
*/
|
|
146
|
+
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;
|
|
147
|
+
/**
|
|
148
|
+
* Strip a leading hyphen (produced when the first char is uppercase).
|
|
149
|
+
*/
|
|
150
|
+
type StripLeadingHyphen<S extends string> = S extends `-${infer R}` ? R : S;
|
|
151
|
+
/**
|
|
152
|
+
* Convert a camelCase string to kebab-case at the type level.
|
|
153
|
+
* Aligned with the runtime `toKebabCase()` function in schema-extractor.ts.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* type R = KebabCase<"myOption">; // "my-option"
|
|
157
|
+
* type R2 = KebabCase<"already">; // "already"
|
|
158
|
+
*/
|
|
159
|
+
type KebabCase<S extends string> = StripLeadingHyphen<KebabCaseInner<S>>;
|
|
160
|
+
/**
|
|
161
|
+
* Add both camelCase and kebab-case variants for every key in T.
|
|
162
|
+
*
|
|
163
|
+
* Given `{ "my-option": string }`, produces
|
|
164
|
+
* `{ "my-option": string } & { myOption: string }`.
|
|
165
|
+
*
|
|
166
|
+
* Given `{ myOption: string }`, produces
|
|
167
|
+
* `{ myOption: string } & { "my-option": string }`.
|
|
168
|
+
*
|
|
169
|
+
* Keys that are identical in both cases (e.g. single-word keys) are not duplicated.
|
|
170
|
+
* Uses a distributive conditional type so it works correctly with discriminated unions.
|
|
171
|
+
*/
|
|
172
|
+
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;
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region ../core/src/core/case-proxy.d.ts
|
|
175
|
+
/**
|
|
176
|
+
* Wrap an args object with a Proxy that allows dual-case access.
|
|
177
|
+
*
|
|
178
|
+
* Given `{ "my-option": "value" }`, both `obj["my-option"]` and `obj.myOption`
|
|
179
|
+
* will return `"value"`.
|
|
180
|
+
*
|
|
181
|
+
* - `Object.keys()`, `JSON.stringify()`, and spread return only the original keys.
|
|
182
|
+
* - The `in` operator detects both case variants.
|
|
183
|
+
*/
|
|
184
|
+
declare function createDualCaseProxy<T extends Record<string, unknown>>(obj: T): WithCaseVariants<T>;
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region ../core/src/core/command.d.ts
|
|
187
|
+
/**
|
|
188
|
+
* Infer args type from schema, defaults to empty object if undefined.
|
|
189
|
+
* Wraps with WithCaseVariants so both camelCase and kebab-case access is typed.
|
|
190
|
+
*
|
|
191
|
+
* politty's internal validator-free descriptors are checked before the
|
|
192
|
+
* schema-library branch: they present themselves as `ArgsSchema` at the
|
|
193
|
+
* type level (see `InternalArgsSchema`), so without the brand check they
|
|
194
|
+
* would fall into `z.infer` and lose their field types.
|
|
195
|
+
*/
|
|
196
|
+
type InferArgs<TArgsSchema> = TArgsSchema extends InternalArgsSchema<infer TInternalOut> ? WithCaseVariants<TInternalOut> : TArgsSchema extends SchemaLike ? WithCaseVariants<InferSchemaOutput<TArgsSchema>> : Record<string, never>;
|
|
197
|
+
/**
|
|
198
|
+
* Merge local args with global args.
|
|
199
|
+
* No-op when TGlobalArgs is empty (default GlobalArgs not extended).
|
|
200
|
+
* Wraps TGlobalArgs with WithCaseVariants for dual-case access.
|
|
201
|
+
*/
|
|
202
|
+
type MergedArgs<TLocalArgs, TGlobalArgs> = IsEmpty<TGlobalArgs> extends true ? TLocalArgs : TLocalArgs & WithCaseVariants<TGlobalArgs>;
|
|
203
|
+
/**
|
|
204
|
+
* Add the `$source` helper, which reports whether a given field's final
|
|
205
|
+
* value came from an explicit CLI token, a `field.env` fallback, or
|
|
206
|
+
* neither (schema default / `prompt` resolution).
|
|
207
|
+
*
|
|
208
|
+
* `name` is typed as a plain `string` (not `keyof T`) since the runtime
|
|
209
|
+
* helper deliberately accepts either camelCase or kebab-case field names
|
|
210
|
+
* (matching `createDualCaseProxy`'s dual-case access) and returns
|
|
211
|
+
* `"default"` for anything it doesn't recognize. A `keyof T`-based type
|
|
212
|
+
* would also be unsound for discriminated-union `args` schemas, where
|
|
213
|
+
* narrowing `args` to one branch doesn't retroactively narrow `$source`'s
|
|
214
|
+
* already-fixed parameter type.
|
|
215
|
+
*/
|
|
216
|
+
type WithArgSource<T> = T & {
|
|
217
|
+
$source?: (name: string) => ArgSource;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Resolve merged args from schema and global args type
|
|
221
|
+
*/
|
|
222
|
+
type ResolvedArgs<TArgsSchema, TGlobalArgs> = WithArgSource<MergedArgs<InferArgs<TArgsSchema>, TGlobalArgs>>;
|
|
223
|
+
/**
|
|
224
|
+
* Config for defining a command
|
|
225
|
+
* @template TArgsSchema - The args schema type (from the CLI's schema library)
|
|
226
|
+
* @template TResult - The return type of run function (void if no run)
|
|
227
|
+
* @template TGlobalArgs - Global args type (from declaration merging or factory)
|
|
228
|
+
*/
|
|
229
|
+
interface DefineCommandConfig<TArgsSchema extends ArgsSchema$1 | undefined, TResult, TGlobalArgs> {
|
|
230
|
+
name: string;
|
|
231
|
+
description?: string;
|
|
232
|
+
aliases?: string[];
|
|
233
|
+
args?: TArgsSchema;
|
|
234
|
+
subCommands?: SubCommandsRecord;
|
|
235
|
+
setup?: (context: {
|
|
236
|
+
args: ResolvedArgs<TArgsSchema, TGlobalArgs>;
|
|
237
|
+
}) => void | Promise<void>;
|
|
238
|
+
run?: (args: ResolvedArgs<TArgsSchema, TGlobalArgs>) => TResult;
|
|
239
|
+
cleanup?: (context: {
|
|
240
|
+
args: ResolvedArgs<TArgsSchema, TGlobalArgs>;
|
|
241
|
+
error?: Error | undefined;
|
|
242
|
+
}) => void | Promise<void>;
|
|
243
|
+
notes?: string;
|
|
244
|
+
examples?: Example[];
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The overloaded `defineCommand` signature, parameterized by the args-schema
|
|
248
|
+
* constraint. Core's `defineCommand` uses the Standard-Schema-based
|
|
249
|
+
* {@link ArgsSchema}; adapter packages re-pin the same runtime function to
|
|
250
|
+
* their library's schema type (e.g. `DefineCommandFn<z.ZodType<...>>` in
|
|
251
|
+
* `@politty/zod`) so a schema from the wrong library is rejected at the type
|
|
252
|
+
* level instead of failing at runtime in the registered adapter.
|
|
253
|
+
*/
|
|
254
|
+
interface DefineCommandFn<TArgsBase extends ArgsSchema$1 = ArgsSchema$1> {
|
|
255
|
+
<TArgsSchema extends TArgsBase | undefined = undefined, TResult = void, TGlobalArgs = GlobalArgs>(config: RunnableConfig<TArgsSchema, TResult, TGlobalArgs>): RunnableCommand<TArgsSchema, ResolvedArgs<TArgsSchema, TGlobalArgs>, TResult>;
|
|
256
|
+
<TArgsSchema extends TArgsBase | undefined = undefined, TGlobalArgs = GlobalArgs>(config: NonRunnableConfig<TArgsSchema, TGlobalArgs>): NonRunnableCommand<TArgsSchema, ResolvedArgs<TArgsSchema, TGlobalArgs>>;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* `defineCommand` with a pre-bound global args type — the shape returned by
|
|
260
|
+
* {@link createDefineCommand}. Parameterized by the args-schema constraint
|
|
261
|
+
* for the same adapter re-pinning as {@link DefineCommandFn}.
|
|
262
|
+
*/
|
|
263
|
+
interface BoundDefineCommandFn<TGlobalArgs, TArgsBase extends ArgsSchema$1 = ArgsSchema$1> {
|
|
264
|
+
<TArgsSchema extends TArgsBase | undefined = undefined, TResult = void>(config: RunnableConfig<TArgsSchema, TResult, TGlobalArgs>): RunnableCommand<TArgsSchema, ResolvedArgs<TArgsSchema, TGlobalArgs>, TResult>;
|
|
265
|
+
<TArgsSchema extends TArgsBase | undefined = undefined>(config: NonRunnableConfig<TArgsSchema, TGlobalArgs>): NonRunnableCommand<TArgsSchema, ResolvedArgs<TArgsSchema, TGlobalArgs>>;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* The `createDefineCommand` signature, parameterized by the args-schema
|
|
269
|
+
* constraint for adapter re-pinning (see {@link DefineCommandFn}).
|
|
270
|
+
*/
|
|
271
|
+
interface CreateDefineCommandFn<TArgsBase extends ArgsSchema$1 = ArgsSchema$1> {
|
|
272
|
+
<TGlobalArgs>(): BoundDefineCommandFn<TGlobalArgs, TArgsBase>;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Config with run function (runnable command)
|
|
276
|
+
*/
|
|
277
|
+
interface RunnableConfig<TArgsSchema extends ArgsSchema$1 | undefined, TResult, TGlobalArgs> extends DefineCommandConfig<TArgsSchema, TResult, TGlobalArgs> {
|
|
278
|
+
run: (args: ResolvedArgs<TArgsSchema, TGlobalArgs>) => TResult;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Config without run function (non-runnable command)
|
|
282
|
+
*/
|
|
283
|
+
interface NonRunnableConfig<TArgsSchema extends ArgsSchema$1 | undefined, TGlobalArgs> extends Omit<DefineCommandConfig<TArgsSchema, void, TGlobalArgs>, "run"> {
|
|
284
|
+
run?: undefined;
|
|
285
|
+
}
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region ../core/src/core/runner.d.ts
|
|
288
|
+
/**
|
|
289
|
+
* Run a command with the given arguments (programmatic/test usage)
|
|
290
|
+
*
|
|
291
|
+
* This function parses arguments, validates them, routes to subcommands,
|
|
292
|
+
* and executes the command. It does NOT call process.exit.
|
|
293
|
+
*
|
|
294
|
+
* @param command - The command to run
|
|
295
|
+
* @param argv - Command line arguments to parse
|
|
296
|
+
* @param options - Run options
|
|
297
|
+
* @returns The result of command execution
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```ts
|
|
301
|
+
* import { defineCommand, runCommand } from "politty";
|
|
302
|
+
*
|
|
303
|
+
* const command = defineCommand({
|
|
304
|
+
* name: "my-cli",
|
|
305
|
+
* args: z.object({ name: z.string() }),
|
|
306
|
+
* run: ({ name }) => console.log(`Hello, ${name}!`),
|
|
307
|
+
* });
|
|
308
|
+
*
|
|
309
|
+
* // In tests
|
|
310
|
+
* const result = await runCommand(command, ["--name", "World"]);
|
|
311
|
+
* expect(result.exitCode).toBe(0);
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
declare function runCommand<TResult = unknown>(command: AnyCommand, argv: string[], options?: RunCommandOptions): Promise<RunResult<TResult>>;
|
|
315
|
+
/**
|
|
316
|
+
* Run a CLI command as the main entry point
|
|
317
|
+
*
|
|
318
|
+
* This function:
|
|
319
|
+
* - Uses process.argv for arguments
|
|
320
|
+
* - Handles SIGINT/SIGTERM signals
|
|
321
|
+
* - Calls process.exit with the appropriate exit code
|
|
322
|
+
* - Invokes `command.runMainHook` once before parsing if set, so plug-ins
|
|
323
|
+
* like `withCompletionCommand` can fire detached background work
|
|
324
|
+
* - Bypasses user `setup`/`cleanup`/`prompt` and required `globalArgs`
|
|
325
|
+
* for registered hidden subcommands whose name starts with `__`
|
|
326
|
+
* (e.g. `__refresh-completion`)
|
|
327
|
+
*
|
|
328
|
+
* @param command - The command to run
|
|
329
|
+
* @param options - Main options (version, debug)
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```ts
|
|
333
|
+
* import { defineCommand, runMain } from "politty";
|
|
334
|
+
*
|
|
335
|
+
* const command = defineCommand({
|
|
336
|
+
* name: "my-cli",
|
|
337
|
+
* run: () => console.log("Hello!"),
|
|
338
|
+
* });
|
|
339
|
+
*
|
|
340
|
+
* runMain(command, { version: "1.0.0" });
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
declare function runMain(command: AnyCommand, options?: MainOptions): Promise<never>;
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region ../core/src/output/help-generator.d.ts
|
|
346
|
+
/**
|
|
347
|
+
* Descriptions for built-in options
|
|
348
|
+
*/
|
|
349
|
+
interface BuiltinOptionDescriptions {
|
|
350
|
+
/** Description for --help option */
|
|
351
|
+
help?: string;
|
|
352
|
+
/** Description for --help-all option */
|
|
353
|
+
helpAll?: string;
|
|
354
|
+
/** Description for --version option */
|
|
355
|
+
version?: string;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Context for command hierarchy
|
|
359
|
+
*/
|
|
360
|
+
interface CommandContext {
|
|
361
|
+
/** Full command path (e.g., ["config", "get"]) */
|
|
362
|
+
commandPath?: string[] | undefined;
|
|
363
|
+
/** Root command name */
|
|
364
|
+
rootName?: string | undefined;
|
|
365
|
+
/** Root command version */
|
|
366
|
+
rootVersion?: string | undefined;
|
|
367
|
+
/** Extracted fields from global args schema */
|
|
368
|
+
globalExtracted?: ExtractedFields | undefined;
|
|
369
|
+
/** When the command was accessed via an alias, the canonical command name */
|
|
370
|
+
aliasFor?: string | undefined;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Options for help generation
|
|
374
|
+
*/
|
|
375
|
+
interface HelpOptions {
|
|
376
|
+
/** Show subcommand list */
|
|
377
|
+
showSubcommands?: boolean | undefined;
|
|
378
|
+
/** Show subcommand options */
|
|
379
|
+
showSubcommandOptions?: boolean | undefined;
|
|
380
|
+
/** Custom descriptions for built-in options */
|
|
381
|
+
descriptions?: BuiltinOptionDescriptions | undefined;
|
|
382
|
+
/** Command hierarchy context */
|
|
383
|
+
context?: CommandContext | undefined;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Generate help text for a command
|
|
387
|
+
*
|
|
388
|
+
* @param command - The command to generate help for
|
|
389
|
+
* @param options - Help generation options
|
|
390
|
+
* @returns Formatted help text
|
|
391
|
+
*/
|
|
392
|
+
declare function generateHelp(command: AnyCommand, options: HelpOptions): string;
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region ../core/src/output/logger.d.ts
|
|
395
|
+
/**
|
|
396
|
+
* Enable or disable color output programmatically
|
|
397
|
+
*/
|
|
398
|
+
declare function setColorEnabled(enabled: boolean): void;
|
|
399
|
+
/**
|
|
400
|
+
* Check if color output is currently enabled
|
|
401
|
+
*/
|
|
402
|
+
declare function isColorEnabled(): boolean;
|
|
403
|
+
/**
|
|
404
|
+
* Semantic style functions for inline text styling
|
|
405
|
+
*/
|
|
406
|
+
declare const styles: {
|
|
407
|
+
success: (text: string) => string;
|
|
408
|
+
error: (text: string) => string;
|
|
409
|
+
warning: (text: string) => string;
|
|
410
|
+
info: (text: string) => string;
|
|
411
|
+
bold: (text: string) => string;
|
|
412
|
+
dim: (text: string) => string;
|
|
413
|
+
italic: (text: string) => string;
|
|
414
|
+
underline: (text: string) => string;
|
|
415
|
+
red: (text: string) => string;
|
|
416
|
+
green: (text: string) => string;
|
|
417
|
+
yellow: (text: string) => string;
|
|
418
|
+
blue: (text: string) => string;
|
|
419
|
+
magenta: (text: string) => string;
|
|
420
|
+
cyan: (text: string) => string;
|
|
421
|
+
white: (text: string) => string;
|
|
422
|
+
gray: (text: string) => string;
|
|
423
|
+
command: (text: string) => string;
|
|
424
|
+
commandName: (text: string) => string;
|
|
425
|
+
option: (text: string) => string;
|
|
426
|
+
optionName: (text: string) => string;
|
|
427
|
+
placeholder: (text: string) => string;
|
|
428
|
+
defaultValue: (text: string) => string;
|
|
429
|
+
required: (text: string) => string;
|
|
430
|
+
description: (text: string) => string;
|
|
431
|
+
sectionHeader: (text: string) => string;
|
|
432
|
+
version: (text: string) => string;
|
|
433
|
+
};
|
|
434
|
+
/**
|
|
435
|
+
* Standardized symbols for CLI output
|
|
436
|
+
*/
|
|
437
|
+
declare const symbols: {
|
|
438
|
+
success: string;
|
|
439
|
+
error: string;
|
|
440
|
+
warning: string;
|
|
441
|
+
info: string;
|
|
442
|
+
bullet: string;
|
|
443
|
+
arrow: string;
|
|
444
|
+
};
|
|
445
|
+
/**
|
|
446
|
+
* Logger for CLI output
|
|
447
|
+
*/
|
|
448
|
+
declare const logger: {
|
|
449
|
+
/**
|
|
450
|
+
* Log informational message
|
|
451
|
+
*/
|
|
452
|
+
info(message: string): void;
|
|
453
|
+
/**
|
|
454
|
+
* Log success message
|
|
455
|
+
*/
|
|
456
|
+
success(message: string): void;
|
|
457
|
+
/**
|
|
458
|
+
* Log warning message
|
|
459
|
+
*/
|
|
460
|
+
warn(message: string): void;
|
|
461
|
+
/**
|
|
462
|
+
* Log error message
|
|
463
|
+
*/
|
|
464
|
+
error(message: string): void;
|
|
465
|
+
/**
|
|
466
|
+
* Log raw message without prefix
|
|
467
|
+
*/
|
|
468
|
+
log(message: string): void;
|
|
469
|
+
/**
|
|
470
|
+
* Log empty line
|
|
471
|
+
*/
|
|
472
|
+
newline(): void;
|
|
473
|
+
/**
|
|
474
|
+
* Log debug message with dim color
|
|
475
|
+
*/
|
|
476
|
+
debug(message: string): void;
|
|
477
|
+
};
|
|
478
|
+
//#endregion
|
|
479
|
+
//#region ../core/src/output/markdown-renderer.d.ts
|
|
480
|
+
/**
|
|
481
|
+
* Lightweight Markdown-to-terminal renderer.
|
|
482
|
+
*
|
|
483
|
+
* Supports a subset of Markdown tailored for CLI help notes:
|
|
484
|
+
* - Inline: bold, italic, inline code, links
|
|
485
|
+
* - Block: paragraphs, unordered/ordered lists, blockquotes, headings,
|
|
486
|
+
* horizontal rules, fenced code blocks
|
|
487
|
+
*/
|
|
488
|
+
/**
|
|
489
|
+
* Apply inline Markdown formatting to a string.
|
|
490
|
+
*
|
|
491
|
+
* Processing order matters to avoid conflicts:
|
|
492
|
+
* 1. Inline code (backticks) — content inside is literal, no further processing
|
|
493
|
+
* 2. Bold (**text**)
|
|
494
|
+
* 3. Italic (*text* or _text_)
|
|
495
|
+
* 4. Links [text](url)
|
|
496
|
+
*/
|
|
497
|
+
declare function renderInline(text: string): string;
|
|
498
|
+
/**
|
|
499
|
+
* Render a Markdown string to styled terminal output.
|
|
500
|
+
*
|
|
501
|
+
* Block-level processing:
|
|
502
|
+
* - Splits input into blocks separated by blank lines
|
|
503
|
+
* - Detects headings, horizontal rules, blockquotes, lists, code blocks, and paragraphs
|
|
504
|
+
* - Applies inline formatting within each block
|
|
505
|
+
*/
|
|
506
|
+
declare function renderMarkdown(markdown: string): string;
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region ../core/src/parser/argv-parser.d.ts
|
|
509
|
+
/**
|
|
510
|
+
* Parsed arguments result
|
|
511
|
+
*/
|
|
512
|
+
interface ParsedArgv {
|
|
513
|
+
/** Named options (--flag, -f) */
|
|
514
|
+
options: Record<string, unknown>;
|
|
515
|
+
/** Positional arguments */
|
|
516
|
+
positionals: string[];
|
|
517
|
+
/** Arguments after -- */
|
|
518
|
+
rest: string[];
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Parser options
|
|
522
|
+
*/
|
|
523
|
+
interface ParserOptions {
|
|
524
|
+
/** Alias map (short -> long) */
|
|
525
|
+
aliasMap?: Map<string, string>;
|
|
526
|
+
/** Boolean flags (no value expected) */
|
|
527
|
+
booleanFlags?: Set<string>;
|
|
528
|
+
/** Array flags (can be repeated) */
|
|
529
|
+
arrayFlags?: Set<string>;
|
|
530
|
+
/**
|
|
531
|
+
* All known canonical option names (as defined in the schema).
|
|
532
|
+
* Used to disambiguate negation: when `--no-flag` or `--noFlag` matches
|
|
533
|
+
* a name in this set, it is treated as a regular option rather than
|
|
534
|
+
* boolean negation of `flag`.
|
|
535
|
+
*/
|
|
536
|
+
definedNames?: Set<string>;
|
|
537
|
+
/**
|
|
538
|
+
* Map from a custom negation CLI name (and camelCase variant) to the
|
|
539
|
+
* canonical field name. Used to recognize user-defined boolean negation
|
|
540
|
+
* options (e.g. `--disable-cache` → `{ cache: false }`).
|
|
541
|
+
*/
|
|
542
|
+
negationMap?: Map<string, string>;
|
|
543
|
+
/**
|
|
544
|
+
* Canonical field names whose default `--no-<name>` / `--no<Name>`
|
|
545
|
+
* negation forms are suppressed. When omitted, every field in
|
|
546
|
+
* `booleanFlags` has default negation suppressed.
|
|
547
|
+
*/
|
|
548
|
+
defaultNegationDisabledFields?: Set<string>;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Parse argv into a flat record
|
|
552
|
+
*
|
|
553
|
+
* Supports:
|
|
554
|
+
* - Long options: --flag, --flag=value, --flag value
|
|
555
|
+
* - Short options: -f, -f=value, -f value
|
|
556
|
+
* - Combined short options: -abc (treated as -a -b -c if all are boolean)
|
|
557
|
+
* - Positional arguments
|
|
558
|
+
* - -- to stop parsing options
|
|
559
|
+
* - Boolean negation: --no-flag, --noFlag (requires `booleanFlags` and `negation: true`)
|
|
560
|
+
*
|
|
561
|
+
* **Note:** When using negation detection (`--noFlag` / `--no-flag`),
|
|
562
|
+
* supply `definedNames` so that options whose names happen to start with
|
|
563
|
+
* "no" (e.g. `noDryRun`) are not mistaken for negation of another flag.
|
|
564
|
+
* Without `definedNames`, all `--noX` forms matching a boolean flag will
|
|
565
|
+
* be treated as negation.
|
|
566
|
+
*
|
|
567
|
+
* @param argv - Command line arguments
|
|
568
|
+
* @param options - Parser options
|
|
569
|
+
* @returns Parsed arguments
|
|
570
|
+
*/
|
|
571
|
+
declare function parseArgv(argv: string[], options?: ParserOptions): ParsedArgv;
|
|
572
|
+
//#endregion
|
|
573
|
+
//#region ../core/src/validator/args-validator.d.ts
|
|
574
|
+
/**
|
|
575
|
+
* Format validation errors for display
|
|
576
|
+
*/
|
|
577
|
+
declare function formatValidationErrors(errors: ValidationError[]): string;
|
|
578
|
+
//#endregion
|
|
579
|
+
//#region ../core/src/validator/validation-errors.d.ts
|
|
580
|
+
/**
|
|
581
|
+
* Error thrown when positional argument configuration is invalid
|
|
582
|
+
*/
|
|
583
|
+
declare class PositionalConfigError extends Error {
|
|
584
|
+
constructor(message: string);
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Error thrown when a reserved alias is used
|
|
588
|
+
*/
|
|
589
|
+
declare class ReservedAliasError extends Error {
|
|
590
|
+
constructor(message: string);
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Error thrown when duplicate field names are detected
|
|
594
|
+
*/
|
|
595
|
+
declare class DuplicateFieldError extends Error {
|
|
596
|
+
constructor(message: string);
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Error thrown when duplicate aliases are detected
|
|
600
|
+
*/
|
|
601
|
+
declare class DuplicateAliasError extends Error {
|
|
602
|
+
constructor(message: string);
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Error thrown when fields are case variants of each other (e.g. "my-option" and "myOption")
|
|
606
|
+
*/
|
|
607
|
+
declare class CaseVariantCollisionError extends Error {
|
|
608
|
+
constructor(message: string);
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Error thrown when a custom boolean negation name collides with another
|
|
612
|
+
* field's name, cliName, alias, or another field's negation (including
|
|
613
|
+
* derived camelCase variants).
|
|
614
|
+
*/
|
|
615
|
+
declare class DuplicateNegationError extends Error {
|
|
616
|
+
constructor(message: string);
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Error thrown when a field name collides with a reserved, framework-injected
|
|
620
|
+
* key on the final args object (e.g. `$source`).
|
|
621
|
+
*/
|
|
622
|
+
declare class ReservedFieldNameError extends Error {
|
|
623
|
+
constructor(message: string);
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Error thrown when a global field and a same-named local field have
|
|
627
|
+
* different definitions (per `extractFields()`'s type bucket, whether the
|
|
628
|
+
* field is positional, and enum values). Only exactly-matching definitions
|
|
629
|
+
* are allowed to share a name across global/local schemas — anything else
|
|
630
|
+
* is rejected at validation time rather than risking a value from one
|
|
631
|
+
* schema silently flowing into the other.
|
|
632
|
+
*/
|
|
633
|
+
declare class FieldTypeConflictError extends Error {
|
|
634
|
+
constructor(message: string);
|
|
635
|
+
}
|
|
636
|
+
//#endregion
|
|
637
|
+
//#region ../core/src/validator/command-validator.d.ts
|
|
638
|
+
/**
|
|
639
|
+
* Error detail for command validation
|
|
640
|
+
*/
|
|
641
|
+
interface CommandValidationError {
|
|
642
|
+
/** Path to the command (e.g., ["cli", "build", "watch"]) */
|
|
643
|
+
commandPath: string[];
|
|
644
|
+
/** Error type */
|
|
645
|
+
type: "duplicate_field" | "duplicate_alias" | "invalid_alias" | "positional_config" | "reserved_alias" | "reserved_field_name" | "case_variant_collision" | "duplicate_negation" | "field_type_conflict";
|
|
646
|
+
/** Error message */
|
|
647
|
+
message: string;
|
|
648
|
+
/** Related field name (if applicable) */
|
|
649
|
+
field?: string;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Result of command validation
|
|
653
|
+
*/
|
|
654
|
+
type CommandValidationResult = {
|
|
655
|
+
valid: true;
|
|
656
|
+
} | {
|
|
657
|
+
valid: false;
|
|
658
|
+
errors: CommandValidationError[];
|
|
659
|
+
};
|
|
660
|
+
/**
|
|
661
|
+
* Options for validateCommand
|
|
662
|
+
*/
|
|
663
|
+
interface ValidateCommandOptions {
|
|
664
|
+
/** Starting command path (for nested validation) */
|
|
665
|
+
commandPath?: string[];
|
|
666
|
+
/**
|
|
667
|
+
* Global args schema to check the command tree against for cross-schema
|
|
668
|
+
* field collisions (case-variant collisions and `FieldTypeConflictError`
|
|
669
|
+
* conflicts) -- the same check `runCommand()` performs per-invocation at
|
|
670
|
+
* parse time, but here applied eagerly to every command and subcommand
|
|
671
|
+
* regardless of which subcommand path actually gets invoked at runtime.
|
|
672
|
+
*/
|
|
673
|
+
globalArgs?: ArgsSchema$1;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Validate that no duplicate field names exist
|
|
677
|
+
*
|
|
678
|
+
* @param extracted - Extracted fields from schema
|
|
679
|
+
* @throws {DuplicateFieldError} If duplicate field names are found
|
|
680
|
+
*/
|
|
681
|
+
declare function validateDuplicateFields(extracted: ExtractedFields): void;
|
|
682
|
+
/**
|
|
683
|
+
* Validate that no duplicate aliases exist
|
|
684
|
+
*
|
|
685
|
+
* Also checks for conflicts between aliases and field names
|
|
686
|
+
*
|
|
687
|
+
* @param extracted - Extracted fields from schema
|
|
688
|
+
* @throws {DuplicateAliasError} If duplicate aliases are found or alias conflicts with field name
|
|
689
|
+
*/
|
|
690
|
+
declare function validateDuplicateAliases(extracted: ExtractedFields): void;
|
|
691
|
+
/**
|
|
692
|
+
* Validate positional argument configuration
|
|
693
|
+
*
|
|
694
|
+
* Rules:
|
|
695
|
+
* - Array positional arguments must be the last positional
|
|
696
|
+
* - No positional arguments can follow an array positional
|
|
697
|
+
* - Required positional arguments cannot follow optional positional arguments
|
|
698
|
+
* - Array positional and optional positional cannot be used together (ambiguous parsing)
|
|
699
|
+
*
|
|
700
|
+
* @param extracted - Extracted fields from schema
|
|
701
|
+
* @throws {PositionalConfigError} If configuration is invalid
|
|
702
|
+
*/
|
|
703
|
+
declare function validatePositionalConfig(extracted: ExtractedFields): void;
|
|
704
|
+
/**
|
|
705
|
+
* Validate that no reserved aliases are used without explicit override
|
|
706
|
+
*
|
|
707
|
+
* Reserved aliases:
|
|
708
|
+
* - 'h' is reserved for --help
|
|
709
|
+
* - 'H' is reserved for --help-all
|
|
710
|
+
*
|
|
711
|
+
* Users can override these by setting overrideBuiltinAlias: true
|
|
712
|
+
*
|
|
713
|
+
* @param extracted - Extracted fields from schema
|
|
714
|
+
* @param _hasSubCommands - Whether the command has subcommands (reserved for future use)
|
|
715
|
+
* @throws {ReservedAliasError} If a reserved alias is used without override flag
|
|
716
|
+
*/
|
|
717
|
+
declare function validateReservedAliases(extracted: ExtractedFields, _hasSubCommands: boolean): void;
|
|
718
|
+
/**
|
|
719
|
+
* Validate that no field name starts with `$`
|
|
720
|
+
*
|
|
721
|
+
* The `$` prefix is reserved for framework-injected helpers on the final
|
|
722
|
+
* args object (e.g. `$source`), and is unusable as a real CLI flag anyway
|
|
723
|
+
* since an unquoted `$name` gets shell-expanded before the program sees it.
|
|
724
|
+
*
|
|
725
|
+
* Checking `field.name` alone is sufficient: aliases can't start with `$`
|
|
726
|
+
* (schema extraction already restricts alias characters to `[A-Za-z0-9-]`),
|
|
727
|
+
* and `cliName` is derived from `name` via `toKebabCase`, which never strips
|
|
728
|
+
* or moves a leading `$`. See {@link checkReservedFieldNames}.
|
|
729
|
+
*
|
|
730
|
+
* @param extracted - Extracted fields from schema
|
|
731
|
+
* @throws {ReservedFieldNameError} If a field name starts with "$"
|
|
732
|
+
*/
|
|
733
|
+
declare function validateReservedFieldNames(extracted: ExtractedFields): void;
|
|
734
|
+
/**
|
|
735
|
+
* Validate that custom boolean negation names do not collide with anything
|
|
736
|
+
*
|
|
737
|
+
* @param extracted - Extracted fields from schema
|
|
738
|
+
* @throws {DuplicateNegationError} If a colliding negation is found
|
|
739
|
+
*/
|
|
740
|
+
declare function validateDuplicateNegations(extracted: ExtractedFields): void;
|
|
741
|
+
/**
|
|
742
|
+
* Validate that no case-variant collisions exist
|
|
743
|
+
*
|
|
744
|
+
* @param extracted - Extracted fields from schema
|
|
745
|
+
* @throws {CaseVariantCollisionError} If case-variant collisions are found
|
|
746
|
+
*/
|
|
747
|
+
declare function validateCaseVariantCollisions(extracted: ExtractedFields): void;
|
|
748
|
+
/**
|
|
749
|
+
* Validate that no cross-schema collisions exist between two schemas
|
|
750
|
+
* (e.g., global args and command args): neither a case-variant collision
|
|
751
|
+
* (same canonical name, different spelling) nor a same-named field with a
|
|
752
|
+
* different definition (same spelling, but the two schemas don't agree on
|
|
753
|
+
* what values are valid).
|
|
754
|
+
*
|
|
755
|
+
* @param extractedA - Extracted fields from first schema (e.g., global args)
|
|
756
|
+
* @param extractedB - Extracted fields from second schema (e.g., command args)
|
|
757
|
+
* @throws {CaseVariantCollisionError} If cross-schema case-variant collisions are found
|
|
758
|
+
* @throws {FieldTypeConflictError} If a same-named field has a different definition on each schema
|
|
759
|
+
*/
|
|
760
|
+
declare function validateCrossSchemaCollisions(extractedA: ExtractedFields, extractedB: ExtractedFields): void;
|
|
761
|
+
/**
|
|
762
|
+
* Validate a command and all its subcommands recursively
|
|
763
|
+
*
|
|
764
|
+
* This function collects all validation errors without throwing,
|
|
765
|
+
* making it suitable for test assertions.
|
|
766
|
+
*
|
|
767
|
+
* @param command - The command to validate
|
|
768
|
+
* @param options - Validation options
|
|
769
|
+
* @returns Validation result with all errors collected
|
|
770
|
+
*
|
|
771
|
+
* @example
|
|
772
|
+
* ```ts
|
|
773
|
+
* const result = await validateCommand(myCommand);
|
|
774
|
+
* if (!result.valid) {
|
|
775
|
+
* console.error(result.errors);
|
|
776
|
+
* }
|
|
777
|
+
* ```
|
|
778
|
+
*/
|
|
779
|
+
declare function validateCommand(command: AnyCommand, options?: ValidateCommandOptions): Promise<CommandValidationResult>;
|
|
780
|
+
/**
|
|
781
|
+
* Format command validation errors for display
|
|
782
|
+
*
|
|
783
|
+
* @param errors - Array of validation errors
|
|
784
|
+
* @returns Formatted error message
|
|
785
|
+
*/
|
|
786
|
+
declare function formatCommandValidationErrors(errors: CommandValidationError[]): string;
|
|
787
|
+
//#endregion
|
|
788
|
+
//#region src/index.d.ts
|
|
789
|
+
/**
|
|
790
|
+
* Supported schema types for args in this package: zod schemas whose
|
|
791
|
+
* output is an object. Narrows `@politty/core`'s Standard-Schema-based
|
|
792
|
+
* `ArgsSchema` back to politty's historical zod-typed public surface.
|
|
793
|
+
*/
|
|
794
|
+
type ArgsSchema = z.ZodType<Record<string, any>>;
|
|
795
|
+
declare const defineCommand: DefineCommandFn<ArgsSchema>;
|
|
796
|
+
declare const createDefineCommand: CreateDefineCommandFn<ArgsSchema>;
|
|
797
|
+
declare const arg: ArgFn<z.ZodType>;
|
|
798
|
+
//#endregion
|
|
799
|
+
export { type AnyCommand, type ArgFn, type ArgMeta, type ArgSource, ArgsSchema, type BoundDefineCommandFn, 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 CreateDefineCommandFn, type CustomCompletion, type DefineCommandFn, DuplicateAliasError, DuplicateFieldError, DuplicateNegationError, type DynamicCompletionCandidate, type DynamicCompletionContext, type DynamicCompletionResolver, type DynamicCompletionResult, type EffectContext, type Example, type ExpandCandidate, type ExpandCompletion, type ExtractedFields, FieldTypeConflictError, type GenerateBundledCompletionWorkerOptions, type GenerateBundledCompletionWorkerResult, type GenerateCompileCacheShimOptions, type GenerateCompileCacheShimResult, type GlobalArgs, type GlobalCleanupContext, type GlobalSetupContext, type HelpOptions, type InferSchemaOutput, 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, ReservedFieldNameError, type ResolvedExpandCandidate, type ResolvedFieldMeta, type RunCommandOptions, type RunResult, type RunResultFailure, type RunResultSuccess, type RunnableCommand, type SchemaLike, type SetupContext, type SubCommandValue, type SubCommandsRecord, type UnknownKeysMode, type UnknownSubcommandHandler, type ValidateArgMeta, type ValidationError, type ValidationResult, type WithCaseVariants, type WithCompletionOptions, arg, createDefineCommand, createDualCaseProxy, defineCommand, extractFields, formatCommandValidationErrors, formatValidationErrors, generateBundledCompletionWorker, generateCompileCacheShim, 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, validateReservedFieldNames, withCompletionCommand };
|