padrone 1.1.0 → 1.2.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/CHANGELOG.md +38 -1
- package/LICENSE +1 -1
- package/README.md +60 -30
- package/dist/args-CKNh7Dm9.mjs +175 -0
- package/dist/args-CKNh7Dm9.mjs.map +1 -0
- package/dist/chunk-y_GBKt04.mjs +5 -0
- package/dist/codegen/index.d.mts +305 -0
- package/dist/codegen/index.d.mts.map +1 -0
- package/dist/codegen/index.mjs +1348 -0
- package/dist/codegen/index.mjs.map +1 -0
- package/dist/completion.d.mts +64 -0
- package/dist/completion.d.mts.map +1 -0
- package/dist/completion.mjs +417 -0
- package/dist/completion.mjs.map +1 -0
- package/dist/docs/index.d.mts +34 -0
- package/dist/docs/index.d.mts.map +1 -0
- package/dist/docs/index.mjs +404 -0
- package/dist/docs/index.mjs.map +1 -0
- package/dist/formatter-Dvx7jFXr.d.mts +82 -0
- package/dist/formatter-Dvx7jFXr.d.mts.map +1 -0
- package/dist/help-mUIX0T0V.mjs +1195 -0
- package/dist/help-mUIX0T0V.mjs.map +1 -0
- package/dist/index.d.mts +120 -546
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1180 -1197
- package/dist/index.mjs.map +1 -1
- package/dist/test.d.mts +112 -0
- package/dist/test.d.mts.map +1 -0
- package/dist/test.mjs +138 -0
- package/dist/test.mjs.map +1 -0
- package/dist/types-qrtt0135.d.mts +1037 -0
- package/dist/types-qrtt0135.d.mts.map +1 -0
- package/dist/update-check-EbNDkzyV.mjs +146 -0
- package/dist/update-check-EbNDkzyV.mjs.map +1 -0
- package/package.json +61 -21
- package/src/args.ts +365 -0
- package/src/cli/completions.ts +29 -0
- package/src/cli/docs.ts +86 -0
- package/src/cli/doctor.ts +312 -0
- package/src/cli/index.ts +159 -0
- package/src/cli/init.ts +135 -0
- package/src/cli/link.ts +320 -0
- package/src/cli/wrap.ts +152 -0
- package/src/codegen/README.md +118 -0
- package/src/codegen/code-builder.ts +226 -0
- package/src/codegen/discovery.ts +232 -0
- package/src/codegen/file-emitter.ts +73 -0
- package/src/codegen/generators/barrel-file.ts +16 -0
- package/src/codegen/generators/command-file.ts +184 -0
- package/src/codegen/generators/command-tree.ts +124 -0
- package/src/codegen/index.ts +33 -0
- package/src/codegen/parsers/fish.ts +163 -0
- package/src/codegen/parsers/help.ts +378 -0
- package/src/codegen/parsers/merge.ts +158 -0
- package/src/codegen/parsers/zsh.ts +221 -0
- package/src/codegen/schema-to-code.ts +199 -0
- package/src/codegen/template.ts +69 -0
- package/src/codegen/types.ts +143 -0
- package/src/colorizer.ts +2 -2
- package/src/command-utils.ts +501 -0
- package/src/completion.ts +110 -97
- package/src/create.ts +1036 -305
- package/src/docs/index.ts +607 -0
- package/src/errors.ts +131 -0
- package/src/formatter.ts +149 -63
- package/src/help.ts +151 -55
- package/src/index.ts +12 -15
- package/src/interactive.ts +169 -0
- package/src/parse.ts +31 -16
- package/src/repl-loop.ts +317 -0
- package/src/runtime.ts +304 -0
- package/src/shell-utils.ts +83 -0
- package/src/test.ts +285 -0
- package/src/type-helpers.ts +10 -10
- package/src/type-utils.ts +124 -14
- package/src/types.ts +752 -154
- package/src/update-check.ts +244 -0
- package/src/wrap.ts +44 -40
- package/src/zod.d.ts +2 -2
- package/src/options.ts +0 -180
package/dist/index.d.mts
CHANGED
|
@@ -1,586 +1,160 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { _ as PossibleCommands, a as PadroneActionContext, b as PadroneRuntime, c as PadroneCommandResult, d as PadroneProgram, f as PadroneSchema, g as PickCommandByName, h as UpdateCheckConfig, i as AsyncPadroneSchema, l as PadroneParseResult, m as WrapResult, n as AnyPadroneCommand, o as PadroneBuilder, p as WrapConfig, r as AnyPadroneProgram, s as PadroneCommand, t as AnyPadroneBuilder, u as PadronePlugin, v as InteractiveMode, x as REPL_SIGINT, y as InteractivePromptConfig } from "./types-qrtt0135.mjs";
|
|
2
|
+
import { r as HelpInfo } from "./formatter-Dvx7jFXr.mjs";
|
|
3
3
|
|
|
4
|
-
//#region src/
|
|
5
|
-
type HelpFormat = 'text' | 'ansi' | 'console' | 'markdown' | 'html' | 'json';
|
|
6
|
-
type HelpDetail = 'minimal' | 'standard' | 'full';
|
|
4
|
+
//#region src/command-utils.d.ts
|
|
7
5
|
/**
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
name: string;
|
|
12
|
-
description?: string;
|
|
13
|
-
optional: boolean;
|
|
14
|
-
default?: unknown;
|
|
15
|
-
type?: string;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Information about a single option/flag.
|
|
19
|
-
*/
|
|
20
|
-
type HelpOptionInfo = {
|
|
21
|
-
name: string;
|
|
22
|
-
description?: string;
|
|
23
|
-
optional: boolean;
|
|
24
|
-
default?: unknown;
|
|
25
|
-
type?: string;
|
|
26
|
-
enum?: string[];
|
|
27
|
-
aliases?: string[];
|
|
28
|
-
deprecated?: boolean | string;
|
|
29
|
-
hidden?: boolean;
|
|
30
|
-
examples?: unknown[]; /** Environment variable(s) this option can be set from */
|
|
31
|
-
env?: string | string[]; /** Whether this option is an array type (shown as <type...>) */
|
|
32
|
-
variadic?: boolean; /** Whether this option is a boolean (shown as --[no-]option) */
|
|
33
|
-
negatable?: boolean; /** Config file key that maps to this option */
|
|
34
|
-
configKey?: string;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Information about a subcommand (minimal info for listing).
|
|
38
|
-
*/
|
|
39
|
-
type HelpSubcommandInfo = {
|
|
40
|
-
name: string;
|
|
41
|
-
title?: string;
|
|
42
|
-
description?: string;
|
|
43
|
-
aliases?: string[];
|
|
44
|
-
deprecated?: boolean | string;
|
|
45
|
-
hidden?: boolean;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Comprehensive JSON structure for help information.
|
|
49
|
-
* This is the single source of truth that all formatters use.
|
|
50
|
-
*/
|
|
51
|
-
type HelpInfo = {
|
|
52
|
-
/** The full command name (e.g., "cli serve" or "<root>") */name: string; /** Short title for the command */
|
|
53
|
-
title?: string; /** Command description */
|
|
54
|
-
description?: string; /** Alternative names/aliases for this command */
|
|
55
|
-
aliases?: string[]; /** Whether the command is deprecated */
|
|
56
|
-
deprecated?: boolean | string; /** Whether the command is hidden */
|
|
57
|
-
hidden?: boolean; /** Usage string parts for flexible formatting */
|
|
58
|
-
usage: {
|
|
59
|
-
command: string;
|
|
60
|
-
hasSubcommands: boolean;
|
|
61
|
-
hasArguments: boolean;
|
|
62
|
-
hasOptions: boolean;
|
|
63
|
-
}; /** List of subcommands */
|
|
64
|
-
subcommands?: HelpSubcommandInfo[]; /** Positional arguments */
|
|
65
|
-
arguments?: HelpArgumentInfo[]; /** Options/flags (only visible ones, hidden filtered out) */
|
|
66
|
-
options?: HelpOptionInfo[]; /** Full help info for nested commands (used in 'full' detail mode) */
|
|
67
|
-
nestedCommands?: HelpInfo[];
|
|
68
|
-
};
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/help.d.ts
|
|
71
|
-
type HelpOptions = {
|
|
72
|
-
format?: HelpFormat | 'auto';
|
|
73
|
-
detail?: HelpDetail;
|
|
74
|
-
};
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/options.d.ts
|
|
77
|
-
interface PadroneOptionsMeta {
|
|
78
|
-
description?: string;
|
|
79
|
-
alias?: string[] | string;
|
|
80
|
-
deprecated?: boolean | string;
|
|
81
|
-
hidden?: boolean;
|
|
82
|
-
examples?: unknown[];
|
|
83
|
-
}
|
|
84
|
-
type PositionalArgs<TObj> = TObj extends Record<string, any> ? { [K in keyof TObj]: TObj[K] extends Array<any> ? `...${K & string}` : K & string }[keyof TObj] : string;
|
|
85
|
-
/**
|
|
86
|
-
* Meta configuration for options including positional arguments.
|
|
87
|
-
* The `positional` array defines which options are positional arguments and their order.
|
|
88
|
-
* Use '...name' prefix to indicate variadic (rest) arguments, matching JS/TS rest syntax.
|
|
6
|
+
* Brands a schema as async, signaling that its `validate()` may return a Promise.
|
|
7
|
+
* When an async-branded schema is passed to `.arguments()`, `.configFile()`, or `.env()`,
|
|
8
|
+
* the command's `parse()` and `cli()` will return Promises.
|
|
89
9
|
*
|
|
90
10
|
* @example
|
|
91
11
|
* ```ts
|
|
92
|
-
* .
|
|
93
|
-
*
|
|
94
|
-
* })
|
|
12
|
+
* const schema = asyncSchema(z.object({
|
|
13
|
+
* name: z.string(),
|
|
14
|
+
* }).check(async (data) => {
|
|
15
|
+
* // async validation logic
|
|
16
|
+
* }));
|
|
17
|
+
*
|
|
18
|
+
* const program = createPadrone('app')
|
|
19
|
+
* .command('greet', (c) => c.arguments(schema).action((args) => args.name));
|
|
20
|
+
*
|
|
21
|
+
* // parse() now returns Promise<PadroneParseResult>
|
|
22
|
+
* const result = await program.parse('greet --name world');
|
|
95
23
|
* ```
|
|
96
24
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* Array of option names that should be treated as positional arguments.
|
|
100
|
-
* Order in array determines position. Use '...name' prefix for variadic args.
|
|
101
|
-
* @example ['source', '...files', 'dest'] - 'files' captures multiple values
|
|
102
|
-
*/
|
|
103
|
-
positional?: PositionalArgs<TObj>[];
|
|
104
|
-
/**
|
|
105
|
-
* Per-option metadata.
|
|
106
|
-
*/
|
|
107
|
-
options?: { [K in keyof TObj]?: PadroneOptionsMeta };
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region src/type-utils.d.ts
|
|
111
|
-
type SafeString = string & {};
|
|
112
|
-
type IsUnknown<T> = unknown extends T ? true : false;
|
|
113
|
-
type IsAny<T> = any extends T ? true : false;
|
|
114
|
-
type IsNever<T> = [T] extends [never] ? true : false;
|
|
115
|
-
type IsGeneric<T> = IsAny<T> extends true ? true : IsUnknown<T> extends true ? true : IsNever<T> extends true ? true : false;
|
|
116
|
-
type SplitString<TName extends string, TSplitBy extends string = ' '> = TName extends `${infer FirstPart}${TSplitBy}${infer RestParts}` ? [FirstPart, ...SplitString<RestParts, TSplitBy>] : [TName];
|
|
117
|
-
type JoinString<TParts extends string[], TJoinBy extends string = ' '> = TParts extends [infer FirstPart extends string, ...infer RestParts extends string[]] ? RestParts extends [] ? FirstPart : `${FirstPart}${TJoinBy}${JoinString<RestParts, TJoinBy>}` : TParts extends [] ? '' : TParts[number];
|
|
118
|
-
type SplitLastSpace<S extends string> = SplitString<S> extends [...infer Init extends string[], infer Last extends string] ? Init extends [] ? [S, never] : [JoinString<Init>, Last] : [S, never];
|
|
119
|
-
type AnyPartExtends<U, T> = [U] extends [never] ? false : U extends any ? (U extends T ? true : never) : never extends true ? true : false;
|
|
120
|
-
type FullCommandName<TName extends string, TParentName extends string = ''> = TParentName extends '' ? TName : `${TParentName} ${TName}`;
|
|
121
|
-
/**
|
|
122
|
-
* Generate full alias paths by combining parent path with each alias.
|
|
123
|
-
*/
|
|
124
|
-
type FullAliasPaths<TAliases extends string[], TParentName extends string = ''> = TAliases extends [infer First extends string, ...infer Rest extends string[]] ? FullCommandName<First, TParentName> | FullAliasPaths<Rest, TParentName> : never;
|
|
125
|
-
/**
|
|
126
|
-
* Get all paths for a command including its primary path and all alias paths.
|
|
127
|
-
*/
|
|
128
|
-
type GetCommandPathsAndAliases<TCommand extends AnyPadroneCommand> = TCommand['~types']['path'] extends infer Path extends string ? TCommand['~types']['aliases'] extends infer Aliases extends string[] ? TCommand['~types']['parentName'] extends infer ParentName extends string ? Path | FullAliasPaths<Aliases, ParentName> : Path : Path : never;
|
|
129
|
-
type PickCommandByName<TCommands extends AnyPadroneCommand[], TName extends string | AnyPadroneCommand> = TName extends AnyPadroneCommand ? TName : FlattenCommands<TCommands> extends infer Cmd extends AnyPadroneCommand ? Cmd extends AnyPadroneCommand ? TName extends GetCommandPathsAndAliases<Cmd> ? Cmd : never : never : never;
|
|
130
|
-
type FlattenCommands<TCommands extends AnyPadroneCommand[]> = TCommands extends [] ? never : TCommands extends [infer FirstCommand, ...infer RestCommands] ? (RestCommands extends AnyPadroneCommand[] ? FlattenCommands<RestCommands> : never) | (FirstCommand extends AnyPadroneCommand ? FlattenCommands<FirstCommand['~types']['commands']> | FirstCommand : never) : IsAny<TCommands[number]> extends true ? never : TCommands[number];
|
|
131
|
-
/**
|
|
132
|
-
* Get all command paths including alias paths for all commands.
|
|
133
|
-
*/
|
|
134
|
-
type GetCommandPathsOrAliases<TCommands extends AnyPadroneCommand[]> = GetCommandPathsAndAliases<FlattenCommands<TCommands>>;
|
|
135
|
-
/**
|
|
136
|
-
* Find all the commands that are prefixed with a command name or alias.
|
|
137
|
-
* This is needed to avoid matching other commands when followed by a space and another word.
|
|
138
|
-
* For example, let's say `level1` and `level1 level2` are commands.
|
|
139
|
-
* Then `level1 ${string}` would also match `level1 level2`,
|
|
140
|
-
* and it would cause `level1 level2` to not show up in the autocomplete.
|
|
141
|
-
* By excluding those cases, we can ensure autocomplete works correctly.
|
|
142
|
-
*/
|
|
143
|
-
type PrefixedCommands<TCommands extends AnyPadroneCommand[]> = GetCommandPathsOrAliases<TCommands> extends infer CommandNames ? CommandNames extends string ? AnyPartExtends<GetCommandPathsOrAliases<TCommands>, `${CommandNames} ${string}`> extends true ? never : `${CommandNames} ${string}` : never : never;
|
|
144
|
-
/**
|
|
145
|
-
* The possible commands are the commands that can be parsed by the program.
|
|
146
|
-
* This includes the string that are exact matches to a command name or alias, and strings that are prefixed with a command name or alias.
|
|
147
|
-
*/
|
|
148
|
-
type PossibleCommands<TCommands extends AnyPadroneCommand[], TWithPrefixed extends boolean = false, TWithObjects extends boolean = false, TWithFallback extends boolean = true> = GetCommandPathsOrAliases<TCommands> | (TWithPrefixed extends true ? PrefixedCommands<TCommands> : never) | (TWithObjects extends true ? FlattenCommands<TCommands> : never) | (TWithFallback extends true ? SafeString : never);
|
|
149
|
-
type CommandIsUnknownable<TCommand> = IsGeneric<TCommand> extends true ? true : string extends TCommand ? true : SafeString extends TCommand ? true : false;
|
|
150
|
-
/**
|
|
151
|
-
* Match a string to a command by the possible commands.
|
|
152
|
-
* This is done by recursively splitting the string by the last space, and then checking if the prefix is a valid command name or alias.
|
|
153
|
-
* This is needed to avoid matching the top-level command when there are nested commands.
|
|
154
|
-
*/
|
|
155
|
-
type PickCommandByPossibleCommands<TCommands extends AnyPadroneCommand[], TCommand extends PossibleCommands<TCommands, true, true> | SafeString> = CommandIsUnknownable<TCommand> extends true ? FlattenCommands<TCommands> : TCommand extends AnyPadroneCommand ? TCommand : TCommand extends string ? TCommand extends GetCommandPathsOrAliases<TCommands> ? PickCommandByName<TCommands, TCommand> : SplitLastSpace<TCommand> extends [infer Prefix extends string, infer Rest] ? IsNever<Rest> extends true ? PickCommandByName<TCommands, Prefix> : PickCommandByPossibleCommands<TCommands, Prefix> : never : never;
|
|
156
|
-
//#endregion
|
|
157
|
-
//#region src/wrap.d.ts
|
|
158
|
-
/**
|
|
159
|
-
* Configuration options for wrapping an external CLI tool.
|
|
160
|
-
*/
|
|
161
|
-
type WrapConfig<TCommandOpts extends PadroneSchema = PadroneSchema, TWrapOpts extends PadroneSchema = TCommandOpts> = {
|
|
162
|
-
/**
|
|
163
|
-
* The command to execute (e.g., 'git', 'docker', 'npm').
|
|
164
|
-
*/
|
|
165
|
-
command: string;
|
|
166
|
-
/**
|
|
167
|
-
* Optional fixed arguments that always precede the options (e.g., ['commit'] for 'git commit').
|
|
168
|
-
*/
|
|
169
|
-
args?: string[];
|
|
170
|
-
/**
|
|
171
|
-
* Positional argument configuration for the external command.
|
|
172
|
-
* If not provided, defaults to the wrapping command's positional configuration.
|
|
173
|
-
*/
|
|
174
|
-
positional?: string[];
|
|
175
|
-
/**
|
|
176
|
-
* Whether to inherit stdio streams (stdin, stdout, stderr) from the parent process.
|
|
177
|
-
* Default: true
|
|
178
|
-
*/
|
|
179
|
-
inheritStdio?: boolean;
|
|
180
|
-
/**
|
|
181
|
-
* Optional schema that transforms command options to external CLI arguments.
|
|
182
|
-
* The schema's input type should match the command options, and its output type defines
|
|
183
|
-
* the arguments expected by the external command.
|
|
184
|
-
* If not provided, command options are passed through as-is.
|
|
185
|
-
*/
|
|
186
|
-
schema?: TWrapOpts | ((commandOptions: TCommandOpts) => TWrapOpts);
|
|
25
|
+
declare function asyncSchema<T extends PadroneSchema>(schema: T): T & {
|
|
26
|
+
'~async': true;
|
|
187
27
|
};
|
|
188
28
|
/**
|
|
189
|
-
*
|
|
29
|
+
* Builds a completer function for the REPL from the command tree.
|
|
30
|
+
* Completes command names, subcommand names, option names (--foo), and aliases (-f).
|
|
31
|
+
* Also includes dot-prefixed built-in REPL commands (.exit, .clear, .scope, .help, .history).
|
|
190
32
|
*/
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
*/
|
|
195
|
-
exitCode: number;
|
|
196
|
-
/**
|
|
197
|
-
* Standard output from the process (only if inheritStdio is false).
|
|
198
|
-
*/
|
|
199
|
-
stdout?: string;
|
|
200
|
-
/**
|
|
201
|
-
* Standard error from the process (only if inheritStdio is false).
|
|
202
|
-
*/
|
|
203
|
-
stderr?: string;
|
|
204
|
-
/**
|
|
205
|
-
* Whether the process exited successfully (exit code 0).
|
|
206
|
-
*/
|
|
207
|
-
success: boolean;
|
|
208
|
-
};
|
|
209
|
-
//#endregion
|
|
210
|
-
//#region src/types.d.ts
|
|
211
|
-
type UnknownRecord = Record<string, unknown>;
|
|
212
|
-
type EmptyRecord = Record<string, never>;
|
|
213
|
-
type DefaultOpts = UnknownRecord | void;
|
|
214
|
-
/**
|
|
215
|
-
* A schema that supports both validation (StandardSchemaV1) and JSON schema generation (StandardJSONSchemaV1).
|
|
216
|
-
* This is the type required for command arguments and options in Padrone.
|
|
217
|
-
*/
|
|
218
|
-
type PadroneSchema<Input = unknown, Output = Input> = StandardSchemaV1<Input, Output> & StandardJSONSchemaV1<Input, Output>;
|
|
219
|
-
/**
|
|
220
|
-
* Helper type to set aliases on a command type.
|
|
221
|
-
* Uses intersection to override just the aliases while preserving all other type information.
|
|
222
|
-
*/
|
|
223
|
-
type WithAliases<TCommand extends AnyPadroneCommand, TAliases extends string[]> = Omit<TCommand, 'aliases' | '~types'> & {
|
|
224
|
-
aliases?: TAliases;
|
|
225
|
-
'~types': Omit<TCommand['~types'], 'aliases'> & {
|
|
226
|
-
aliases: TAliases;
|
|
227
|
-
};
|
|
228
|
-
};
|
|
229
|
-
type PadroneCommand<TName extends string = string, TParentName extends string = '', TOpts extends PadroneSchema = PadroneSchema<DefaultOpts>, TRes = void, TCommands extends [...AnyPadroneCommand[]] = [], TAliases extends string[] = string[], TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TOpts>> = PadroneSchema<void>, TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TOpts>> = PadroneSchema<void>> = {
|
|
230
|
-
name: TName;
|
|
231
|
-
path: FullCommandName<TName, TParentName>;
|
|
232
|
-
title?: string;
|
|
233
|
-
description?: string;
|
|
234
|
-
version?: string; /** Alternative names that can be used to invoke this command. Derived from the names passed to command(). */
|
|
235
|
-
aliases?: TAliases;
|
|
236
|
-
deprecated?: boolean | string;
|
|
237
|
-
hidden?: boolean;
|
|
238
|
-
needsApproval?: boolean | ((options: TOpts) => Promise<boolean> | boolean);
|
|
239
|
-
options?: TOpts;
|
|
240
|
-
config?: TConfig;
|
|
241
|
-
envSchema?: TEnv;
|
|
242
|
-
meta?: GetMeta<TOpts>;
|
|
243
|
-
handler?: (options: StandardSchemaV1.InferOutput<TOpts>) => TRes; /** List of possible config file names to search for. */
|
|
244
|
-
configFiles?: string[];
|
|
245
|
-
parent?: AnyPadroneCommand;
|
|
246
|
-
commands?: TCommands; /** @deprecated Internal use only */
|
|
247
|
-
'~types': {
|
|
248
|
-
name: TName;
|
|
249
|
-
parentName: TParentName;
|
|
250
|
-
path: FullCommandName<TName, TParentName>;
|
|
251
|
-
aliases: TAliases;
|
|
252
|
-
optionsInput: StandardSchemaV1.InferInput<TOpts>;
|
|
253
|
-
optionsOutput: StandardSchemaV1.InferOutput<TOpts>;
|
|
254
|
-
result: TRes;
|
|
255
|
-
commands: TCommands;
|
|
256
|
-
};
|
|
257
|
-
};
|
|
258
|
-
type AnyPadroneCommand = PadroneCommand<string, any, any, any, [...AnyPadroneCommand[]], string[]>;
|
|
259
|
-
/**
|
|
260
|
-
* Base type for extracting command information from builder or program.
|
|
261
|
-
* Both PadroneBuilder and PadroneProgram share this structure.
|
|
262
|
-
*/
|
|
263
|
-
type CommandTypesBase = {
|
|
264
|
-
'~types': {
|
|
265
|
-
command: AnyPadroneCommand;
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
/**
|
|
269
|
-
* Configuration options for a command.
|
|
270
|
-
*/
|
|
271
|
-
type PadroneCommandConfig = {
|
|
272
|
-
/** A short title for the command, displayed in help. */title?: string; /** A longer description of what the command does. */
|
|
273
|
-
description?: string; /** The version of the command. */
|
|
274
|
-
version?: string; /** Whether the command is deprecated, or a message explaining the deprecation. */
|
|
275
|
-
deprecated?: boolean | string; /** Whether the command should be hidden from help output. */
|
|
276
|
-
hidden?: boolean;
|
|
277
|
-
};
|
|
278
|
-
/**
|
|
279
|
-
* Conditional type that returns either PadroneBuilder or PadroneProgram based on TReturn.
|
|
280
|
-
* Used to avoid repetition in PadroneBuilderMethods return types.
|
|
281
|
-
*/
|
|
282
|
-
type BuilderOrProgram<TReturn extends 'builder' | 'program', TProgramName extends string, TName extends string, TParentName extends string, TOpts extends PadroneSchema, TRes, TCommands extends [...AnyPadroneCommand[]], TParentOpts extends PadroneSchema, TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TOpts>>, TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TOpts>>> = TReturn extends 'builder' ? PadroneBuilder<TProgramName, TName, TParentName, TOpts, TRes, TCommands, TParentOpts, TConfig, TEnv> : PadroneProgram<TProgramName, TName, TParentName, TOpts, TRes, TCommands, TParentOpts, TConfig, TEnv>;
|
|
283
|
-
/**
|
|
284
|
-
* Base builder methods shared between PadroneBuilder and PadroneProgram.
|
|
285
|
-
* These methods are used for defining command structure (options, config, env, action, subcommands).
|
|
286
|
-
*/
|
|
287
|
-
type PadroneBuilderMethods<TProgramName extends string, TName extends string, TParentName extends string, TOpts extends PadroneSchema, TRes, TCommands extends [...AnyPadroneCommand[]], TParentOpts extends PadroneSchema, TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TOpts>>, TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TOpts>>, /** The return type for builder methods - either PadroneBuilder or PadroneProgram */TReturn extends 'builder' | 'program'> = {
|
|
288
|
-
/**
|
|
289
|
-
* Configures command properties like title, description, version, deprecated, and hidden.
|
|
290
|
-
* @example
|
|
291
|
-
* ```ts
|
|
292
|
-
* .configure({
|
|
293
|
-
* title: 'Build Project',
|
|
294
|
-
* description: 'Compiles the project',
|
|
295
|
-
* deprecated: 'Use "compile" instead',
|
|
296
|
-
* })
|
|
297
|
-
* ```
|
|
298
|
-
*/
|
|
299
|
-
configure: (config: PadroneCommandConfig) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TOpts, TRes, TCommands, TParentOpts, TConfig, TEnv>;
|
|
300
|
-
/**
|
|
301
|
-
* Defines the options schema for the command, including positional arguments.
|
|
302
|
-
* Can accept either a schema directly or a function that takes parent options as a base and returns a schema.
|
|
303
|
-
* Use the `positional` array in meta to specify which options are positional args.
|
|
304
|
-
* Use '...name' prefix for variadic (rest) arguments, matching JS/TS rest syntax.
|
|
305
|
-
*
|
|
306
|
-
* @example
|
|
307
|
-
* ```ts
|
|
308
|
-
* // Direct schema
|
|
309
|
-
* .arguments(z.object({
|
|
310
|
-
* source: z.string(),
|
|
311
|
-
* files: z.string().array(),
|
|
312
|
-
* dest: z.string(),
|
|
313
|
-
* recursive: z.boolean().default(false),
|
|
314
|
-
* }), {
|
|
315
|
-
* positional: ['source', '...files', 'dest'],
|
|
316
|
-
* })
|
|
317
|
-
* ```
|
|
318
|
-
*
|
|
319
|
-
* @example
|
|
320
|
-
* ```ts
|
|
321
|
-
* // Function-based schema extending parent options
|
|
322
|
-
* .arguments((parentOpts) => {
|
|
323
|
-
* return z.object({
|
|
324
|
-
* ...parentOpts.shape,
|
|
325
|
-
* verbose: z.boolean().default(false),
|
|
326
|
-
* });
|
|
327
|
-
* })
|
|
328
|
-
* ```
|
|
329
|
-
*/
|
|
330
|
-
arguments: <TNewOpts extends PadroneSchema = PadroneSchema<void>>(options?: TNewOpts | ((parentOptions: TParentOpts) => TNewOpts), meta?: GetMeta<TNewOpts>) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TNewOpts, TRes, TCommands, TParentOpts, TConfig, TEnv>;
|
|
331
|
-
/**
|
|
332
|
-
* Configures config file path(s) and schema for parsing config files.
|
|
333
|
-
* @example
|
|
334
|
-
* ```ts
|
|
335
|
-
* .configFile('config.json', z.object({ port: z.number() }))
|
|
336
|
-
* ```
|
|
337
|
-
*/
|
|
338
|
-
configFile: <TNewConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TOpts>> = TOpts>(file: string | string[] | undefined, schema?: TNewConfig | ((optionsSchema: TOpts) => TNewConfig)) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TOpts, TRes, TCommands, TParentOpts, TNewConfig, TEnv>;
|
|
339
|
-
/**
|
|
340
|
-
* Configures environment variable schema for parsing env vars into options.
|
|
341
|
-
* The schema should transform environment variables (typically SCREAMING_SNAKE_CASE)
|
|
342
|
-
* into the option names used by the command.
|
|
343
|
-
* @example
|
|
344
|
-
* ```ts
|
|
345
|
-
* .env(z.object({ MY_APP_PORT: z.coerce.number() }).transform(e => ({ port: e.MY_APP_PORT })))
|
|
346
|
-
* ```
|
|
347
|
-
*/
|
|
348
|
-
env: <TNewEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TOpts>> = TOpts>(schema: TNewEnv | ((optionsSchema: TOpts) => TNewEnv)) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TOpts, TRes, TCommands, TParentOpts, TConfig, TNewEnv>;
|
|
349
|
-
/**
|
|
350
|
-
* Defines the handler function to be executed when the command is run.
|
|
351
|
-
*/
|
|
352
|
-
action: <TNewRes>(handler?: (options: StandardSchemaV1.InferOutput<TOpts>) => TNewRes) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TOpts, TNewRes, TCommands, TParentOpts, TConfig, TEnv>;
|
|
353
|
-
/**
|
|
354
|
-
* Wraps an external CLI tool with optional schema transformation.
|
|
355
|
-
* The config can include a schema that transforms command options to external CLI arguments.
|
|
356
|
-
*
|
|
357
|
-
* @example
|
|
358
|
-
* ```ts
|
|
359
|
-
* // No transformation - pass options as-is
|
|
360
|
-
* .arguments(z.object({
|
|
361
|
-
* message: z.string(),
|
|
362
|
-
* }))
|
|
363
|
-
* .wrap({
|
|
364
|
-
* command: 'echo',
|
|
365
|
-
* })
|
|
366
|
-
* ```
|
|
367
|
-
*
|
|
368
|
-
* @example
|
|
369
|
-
* ```ts
|
|
370
|
-
* // With transformation schema
|
|
371
|
-
* .arguments(z.object({
|
|
372
|
-
* message: z.string(),
|
|
373
|
-
* all: z.boolean().optional(),
|
|
374
|
-
* }), {
|
|
375
|
-
* positional: ['message'],
|
|
376
|
-
* })
|
|
377
|
-
* .wrap({
|
|
378
|
-
* command: 'git',
|
|
379
|
-
* args: ['commit'],
|
|
380
|
-
* positional: ['m'],
|
|
381
|
-
* schema: z.object({
|
|
382
|
-
* message: z.string(),
|
|
383
|
-
* all: z.boolean().optional(),
|
|
384
|
-
* }).transform(opts => ({
|
|
385
|
-
* m: opts.message,
|
|
386
|
-
* a: opts.all,
|
|
387
|
-
* })),
|
|
388
|
-
* })
|
|
389
|
-
* ```
|
|
390
|
-
*
|
|
391
|
-
* @example
|
|
392
|
-
* ```ts
|
|
393
|
-
* // Using function-based schema for type inference
|
|
394
|
-
* .arguments(z.object({
|
|
395
|
-
* image: z.string(),
|
|
396
|
-
* detach: z.boolean().optional(),
|
|
397
|
-
* }))
|
|
398
|
-
* .wrap({
|
|
399
|
-
* command: 'docker',
|
|
400
|
-
* args: ['run'],
|
|
401
|
-
* positional: ['image'],
|
|
402
|
-
* schema: (cmdOpts) => cmdOpts.transform(opts => ({
|
|
403
|
-
* d: opts.detach,
|
|
404
|
-
* image: opts.image,
|
|
405
|
-
* })),
|
|
406
|
-
* })
|
|
407
|
-
* ```
|
|
408
|
-
*/
|
|
409
|
-
wrap: <TWrapOpts extends PadroneSchema = TOpts>(config: WrapConfig<TOpts, TWrapOpts>) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TOpts, Promise<WrapResult>, TCommands, TParentOpts, TConfig, TEnv>;
|
|
410
|
-
/**
|
|
411
|
-
* Creates a nested command within the current command with the given name and builder function.
|
|
412
|
-
* The name can be a single string or a tuple of [name, ...aliases] where additional strings are aliases.
|
|
413
|
-
* @example
|
|
414
|
-
* ```ts
|
|
415
|
-
* // Single name
|
|
416
|
-
* .command('list', (c) => c.action(() => 'list'))
|
|
417
|
-
*
|
|
418
|
-
* // Name with aliases
|
|
419
|
-
* .command(['list', 'ls', 'l'], (c) => c.action(() => 'list'))
|
|
420
|
-
* ```
|
|
421
|
-
*/
|
|
422
|
-
command: <TNameNested extends string, TAliases extends string[] = [], TBuilder extends CommandTypesBase = PadroneBuilder<TProgramName, TNameNested, FullCommandName<TName, TParentName>, any, void, [], TOpts, any, any>>(name: TNameNested | readonly [TNameNested, ...TAliases], builderFn?: (builder: PadroneBuilder<TProgramName, TNameNested, FullCommandName<TName, TParentName>, PadroneSchema<void>, void, [], TOpts, PadroneSchema<void>, PadroneSchema<void>>) => TBuilder) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TOpts, TRes, TCommands extends [] ? [WithAliases<TBuilder['~types']['command'], TAliases>] : AnyPadroneCommand[] extends TCommands ? [WithAliases<TBuilder['~types']['command'], TAliases>] : [...TCommands, WithAliases<TBuilder['~types']['command'], TAliases>], TParentOpts, TConfig, TEnv>; /** @deprecated Internal use only */
|
|
423
|
-
'~types': {
|
|
424
|
-
programName: TProgramName;
|
|
425
|
-
name: TName;
|
|
426
|
-
parentName: TParentName;
|
|
427
|
-
path: FullCommandName<TName, TParentName>;
|
|
428
|
-
aliases: [];
|
|
429
|
-
options: TOpts;
|
|
430
|
-
result: TRes;
|
|
431
|
-
commands: TCommands;
|
|
432
|
-
command: PadroneCommand<TName, TParentName, TOpts, TRes, TCommands, []>;
|
|
433
|
-
};
|
|
434
|
-
};
|
|
435
|
-
type PadroneBuilder<TProgramName extends string = '', TName extends string = string, TParentName extends string = '', TOpts extends PadroneSchema = PadroneSchema<DefaultOpts>, TRes = void, TCommands extends [...AnyPadroneCommand[]] = [], TParentOpts extends PadroneSchema = PadroneSchema<void>, TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TOpts>> = PadroneSchema<void>, TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TOpts>> = PadroneSchema<void>> = PadroneBuilderMethods<TProgramName, TName, TParentName, TOpts, TRes, TCommands, TParentOpts, TConfig, TEnv, 'builder'>;
|
|
436
|
-
type PadroneProgram<TProgramName extends string = '', TName extends string = string, TParentName extends string = '', TOpts extends PadroneSchema = PadroneSchema<DefaultOpts>, TRes = void, TCommands extends [...AnyPadroneCommand[]] = [], TParentOpts extends PadroneSchema = PadroneSchema<void>, TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TOpts>> = PadroneSchema<void>, TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TOpts>> = PadroneSchema<void>> = PadroneBuilderMethods<TProgramName, TName, TParentName, TOpts, TRes, TCommands, TParentOpts, TConfig, TEnv, 'program'> & {
|
|
437
|
-
/**
|
|
438
|
-
* Runs a command programmatically by name with provided options (including positional args).
|
|
439
|
-
*/
|
|
440
|
-
run: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TOpts, TRes, TCommands>], true, true>>(name: TCommand | SafeString, options: NoInfer<GetOptions<'in', PickCommandByName<[PadroneCommand<'', '', TOpts, TRes, TCommands>], TCommand>>>) => PadroneCommandResult<PickCommandByName<[PadroneCommand<'', '', TOpts, TRes, TCommands>], TCommand>>;
|
|
441
|
-
/**
|
|
442
|
-
* Runs the program as a CLI application, parsing `process.argv` or provided input.
|
|
443
|
-
*/
|
|
444
|
-
cli: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TOpts, TRes, TCommands>], true, true>>(input?: TCommand | SafeString, options?: PadroneParseOptions) => PadroneCommandResult<PickCommandByPossibleCommands<[PadroneCommand<'', '', TOpts, TRes, TCommands>], TCommand>>;
|
|
445
|
-
/**
|
|
446
|
-
* Parses CLI input (or the provided input string) into command, args, and options without executing anything.
|
|
447
|
-
*/
|
|
448
|
-
parse: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TOpts, TRes, TCommands>], true, false>>(input?: TCommand | SafeString, options?: PadroneParseOptions) => PadroneParseResult<PickCommandByPossibleCommands<[PadroneCommand<'', '', TOpts, TRes, TCommands>], TCommand>>;
|
|
449
|
-
/**
|
|
450
|
-
* Converts command and options back into a CLI string.
|
|
451
|
-
*/
|
|
452
|
-
stringify: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TOpts, TRes, TCommands>], false, true>>(command?: TCommand | SafeString, options?: GetOptions<'out', PickCommandByPossibleCommands<[PadroneCommand<'', '', TOpts, TRes, TCommands>], TCommand>>) => string;
|
|
453
|
-
/**
|
|
454
|
-
* Finds a command by name, returning `undefined` if not found.
|
|
455
|
-
*/
|
|
456
|
-
find: <const TFind extends PossibleCommands<[PadroneCommand<'', '', TOpts, TRes, TCommands>], false, true>>(command: TFind | SafeString) => PickCommandByPossibleCommands<[PadroneCommand<'', '', TOpts, TRes, TCommands>], TFind> | undefined;
|
|
457
|
-
/**
|
|
458
|
-
* Generates a type-safe API for invoking commands programmatically.
|
|
459
|
-
*/
|
|
460
|
-
api: () => PadroneAPI<PadroneCommand<'', '', TOpts, TRes, TCommands>>;
|
|
461
|
-
/**
|
|
462
|
-
* Starts an interactive prompt to run commands.
|
|
463
|
-
*/
|
|
464
|
-
/**
|
|
465
|
-
* Starts a REPL (Read-Eval-Print Loop) for running commands interactively.
|
|
466
|
-
*/
|
|
467
|
-
/**
|
|
468
|
-
* Returns a tool definition that can be passed to AI SDK.
|
|
469
|
-
*/
|
|
470
|
-
tool: () => Tool<{
|
|
471
|
-
command: string;
|
|
472
|
-
}>;
|
|
473
|
-
/**
|
|
474
|
-
* Returns the help information for the program or a specific command.
|
|
475
|
-
*/
|
|
476
|
-
help: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TOpts, TRes, TCommands>], false, true>>(command?: TCommand, options?: HelpOptions) => string;
|
|
477
|
-
/**
|
|
478
|
-
* Generates and returns a shell completion script.
|
|
479
|
-
* If shell is not specified, automatically detects the current shell and provides instructions.
|
|
480
|
-
* @param shell - The shell type (bash, zsh, fish, powershell). If not provided, auto-detects.
|
|
481
|
-
* @returns The shell completion script as a string.
|
|
482
|
-
* @example
|
|
483
|
-
* ```ts
|
|
484
|
-
* // Get bash completion script
|
|
485
|
-
* const bashScript = program.completion('bash');
|
|
486
|
-
*
|
|
487
|
-
* // Auto-detect shell and get completion script with instructions
|
|
488
|
-
* const script = program.completion();
|
|
489
|
-
* ```
|
|
490
|
-
*/
|
|
491
|
-
completion: (shell?: 'bash' | 'zsh' | 'fish' | 'powershell') => string;
|
|
492
|
-
};
|
|
493
|
-
type AnyPadroneProgram = PadroneProgram<string, string, string, any, any, [...AnyPadroneCommand[]]>;
|
|
494
|
-
type PadroneCommandResult<TCommand extends AnyPadroneCommand = AnyPadroneCommand> = PadroneParseResult<TCommand> & {
|
|
495
|
-
result: GetResults<TCommand>;
|
|
496
|
-
};
|
|
497
|
-
/**
|
|
498
|
-
* Options for parsing CLI input.
|
|
499
|
-
*/
|
|
500
|
-
type PadroneParseOptions = {
|
|
501
|
-
/**
|
|
502
|
-
* Raw environment variables to use for env schema validation.
|
|
503
|
-
* If not provided, process.env will be used.
|
|
504
|
-
*/
|
|
505
|
-
env?: Record<string, string | undefined>;
|
|
506
|
-
/**
|
|
507
|
-
* Pre-parsed environment data to use directly (bypasses env schema validation).
|
|
508
|
-
* Keys should match option names.
|
|
509
|
-
*/
|
|
510
|
-
envData?: Record<string, unknown>;
|
|
511
|
-
/**
|
|
512
|
-
* Config file data to use for config binding.
|
|
513
|
-
* This should be the parsed content of a config file (JSON, YAML, etc.).
|
|
514
|
-
*/
|
|
515
|
-
configData?: Record<string, unknown>;
|
|
516
|
-
};
|
|
517
|
-
type PadroneParseResult<TCommand extends AnyPadroneCommand = AnyPadroneCommand> = {
|
|
518
|
-
command: TCommand;
|
|
519
|
-
options?: GetOptions<'out', TCommand>;
|
|
520
|
-
optionsResult?: StandardSchemaV1.Result<GetOptions<'out', TCommand>>;
|
|
521
|
-
};
|
|
522
|
-
type PadroneAPI<TCommand extends AnyPadroneCommand> = PadroneAPICommand<TCommand> & { [K in TCommand['~types']['commands'][number] as K['name']]: PadroneAPI<K> };
|
|
523
|
-
type PadroneAPICommand<TCommand extends AnyPadroneCommand> = (options: GetOptions<'in', TCommand>) => GetResults<TCommand>;
|
|
524
|
-
type NormalizeOptions<TOptions> = IsGeneric<TOptions> extends true ? void | EmptyRecord : TOptions;
|
|
525
|
-
type GetOptions<TDir extends 'in' | 'out', TCommand extends AnyPadroneCommand> = TDir extends 'in' ? NormalizeOptions<TCommand['~types']['optionsInput']> : NormalizeOptions<TCommand['~types']['optionsOutput']>;
|
|
526
|
-
type GetResults<TCommand extends AnyPadroneCommand> = ReturnType<NonNullable<TCommand['handler']>>;
|
|
527
|
-
type GetMeta<TOpts extends PadroneSchema> = PadroneMeta<NonNullable<StandardSchemaV1.InferInput<TOpts>>>;
|
|
33
|
+
declare function buildReplCompleter(rootCommand: AnyPadroneCommand, builtins: {
|
|
34
|
+
inScope?: boolean;
|
|
35
|
+
}): (line: string) => [string[], string];
|
|
528
36
|
//#endregion
|
|
529
37
|
//#region src/create.d.ts
|
|
530
38
|
declare function createPadrone<TProgramName extends string>(name: TProgramName): PadroneProgram<TProgramName, '', ''>;
|
|
531
39
|
//#endregion
|
|
532
|
-
//#region src/
|
|
40
|
+
//#region src/errors.d.ts
|
|
533
41
|
/**
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
42
|
+
* Structured error hierarchy for Padrone CLI framework.
|
|
43
|
+
*
|
|
44
|
+
* All Padrone errors extend `PadroneError`, which carries an exit code,
|
|
45
|
+
* optional suggestions, and context about which command/phase produced the error.
|
|
46
|
+
* This allows callers to distinguish user errors (bad input) from bugs (unexpected throws)
|
|
47
|
+
* and to present formatted, actionable error messages.
|
|
539
48
|
*/
|
|
540
|
-
type
|
|
49
|
+
type PadroneErrorOptions = {
|
|
50
|
+
/** Process exit code. Defaults to 1. */exitCode?: number; /** Actionable suggestions shown to the user (e.g. "Use --env production"). */
|
|
51
|
+
suggestions?: string[]; /** The command path that produced the error (e.g. "deploy staging"). */
|
|
52
|
+
command?: string; /** The phase where the error occurred. */
|
|
53
|
+
phase?: 'parse' | 'validate' | 'execute' | 'config'; /** Original cause for error chaining. */
|
|
54
|
+
cause?: unknown;
|
|
55
|
+
};
|
|
541
56
|
/**
|
|
542
|
-
*
|
|
57
|
+
* Base error class for all Padrone errors.
|
|
58
|
+
* Carries structured metadata for user-friendly formatting and programmatic handling.
|
|
59
|
+
*
|
|
543
60
|
* @example
|
|
544
61
|
* ```ts
|
|
545
|
-
*
|
|
62
|
+
* throw new PadroneError('Something went wrong', {
|
|
63
|
+
* exitCode: 1,
|
|
64
|
+
* suggestions: ['Try --help for usage information'],
|
|
65
|
+
* });
|
|
546
66
|
* ```
|
|
547
67
|
*/
|
|
548
|
-
|
|
68
|
+
declare class PadroneError extends Error {
|
|
69
|
+
readonly exitCode: number;
|
|
70
|
+
readonly suggestions: string[];
|
|
71
|
+
readonly command?: string;
|
|
72
|
+
readonly phase?: 'parse' | 'validate' | 'execute' | 'config';
|
|
73
|
+
constructor(message: string, options?: PadroneErrorOptions);
|
|
74
|
+
/**
|
|
75
|
+
* Returns a serializable representation of the error,
|
|
76
|
+
* suitable for non-terminal runtimes (web UIs, APIs, etc.).
|
|
77
|
+
*/
|
|
78
|
+
toJSON(): {
|
|
79
|
+
name: string;
|
|
80
|
+
message: string;
|
|
81
|
+
exitCode: number;
|
|
82
|
+
suggestions: string[];
|
|
83
|
+
command?: string;
|
|
84
|
+
phase?: string;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
549
87
|
/**
|
|
550
|
-
*
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
88
|
+
* Thrown when command routing fails — unknown command, unexpected arguments, etc.
|
|
89
|
+
*/
|
|
90
|
+
declare class RoutingError extends PadroneError {
|
|
91
|
+
constructor(message: string, options?: PadroneErrorOptions);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Thrown when argument or schema validation fails.
|
|
95
|
+
* Carries the structured issues from the schema validator.
|
|
96
|
+
*/
|
|
97
|
+
declare class ValidationError extends PadroneError {
|
|
98
|
+
readonly issues: readonly {
|
|
99
|
+
path?: PropertyKey[];
|
|
100
|
+
message: string;
|
|
101
|
+
}[];
|
|
102
|
+
constructor(message: string, issues: readonly {
|
|
103
|
+
path?: PropertyKey[];
|
|
104
|
+
message: string;
|
|
105
|
+
}[], options?: PadroneErrorOptions);
|
|
106
|
+
toJSON(): {
|
|
107
|
+
issues: {
|
|
108
|
+
path: string[] | undefined;
|
|
109
|
+
message: string;
|
|
110
|
+
}[];
|
|
111
|
+
name: string;
|
|
112
|
+
message: string;
|
|
113
|
+
exitCode: number;
|
|
114
|
+
suggestions: string[];
|
|
115
|
+
command?: string;
|
|
116
|
+
phase?: string;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Thrown when config file loading or validation fails.
|
|
555
121
|
*/
|
|
556
|
-
|
|
122
|
+
declare class ConfigError extends PadroneError {
|
|
123
|
+
constructor(message: string, options?: PadroneErrorOptions);
|
|
124
|
+
}
|
|
557
125
|
/**
|
|
558
|
-
*
|
|
559
|
-
* This is the
|
|
126
|
+
* Thrown from user action handlers to surface structured errors with exit codes and suggestions.
|
|
127
|
+
* This is the primary error class users should throw from their command actions.
|
|
128
|
+
*
|
|
560
129
|
* @example
|
|
561
130
|
* ```ts
|
|
562
|
-
*
|
|
131
|
+
* throw new ActionError('Missing environment', {
|
|
132
|
+
* exitCode: 1,
|
|
133
|
+
* suggestions: ['Use --env production or --env staging'],
|
|
134
|
+
* });
|
|
563
135
|
* ```
|
|
564
136
|
*/
|
|
565
|
-
|
|
137
|
+
declare class ActionError extends PadroneError {
|
|
138
|
+
constructor(message: string, options?: PadroneErrorOptions);
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/type-helpers.d.ts
|
|
566
142
|
/**
|
|
567
|
-
* Extracts the input type of the
|
|
568
|
-
* This represents the raw environment variables shape (e.g., { PORT: string }).
|
|
143
|
+
* Extracts the input type of the arguments schema from a command.
|
|
569
144
|
* @example
|
|
570
145
|
* ```ts
|
|
571
|
-
* type
|
|
146
|
+
* type Args = InferArgsInput<typeof myCommand>;
|
|
572
147
|
* ```
|
|
573
148
|
*/
|
|
574
|
-
type
|
|
149
|
+
type InferArgsInput<T extends AnyPadroneCommand> = T['~types']['argsInput'];
|
|
575
150
|
/**
|
|
576
|
-
* Extracts the output type of the
|
|
577
|
-
* This is the type after transformation, which should match the options shape.
|
|
151
|
+
* Extracts the output type of the arguments schema from a command.
|
|
578
152
|
* @example
|
|
579
153
|
* ```ts
|
|
580
|
-
* type
|
|
154
|
+
* type Args = InferArgsOutput<typeof myCommand>;
|
|
581
155
|
* ```
|
|
582
156
|
*/
|
|
583
|
-
type
|
|
157
|
+
type InferArgsOutput<T extends AnyPadroneCommand> = T['~types']['argsOutput'];
|
|
584
158
|
/**
|
|
585
159
|
* Gets a command type by its path from a program or command tree.
|
|
586
160
|
* Supports both full paths (e.g., "config set") and alias paths.
|
|
@@ -598,5 +172,5 @@ type InferEnvOutput<T extends AnyPadroneCommand> = T['envSchema'] extends Padron
|
|
|
598
172
|
*/
|
|
599
173
|
type InferCommand<T extends AnyPadroneCommand | AnyPadroneProgram, TPath extends PossibleCommands<T extends AnyPadroneCommand ? [T] : T['~types']['commands'], true, true>> = T extends AnyPadroneProgram ? PickCommandByName<[PadroneCommand<'', '', any, any, T['~types']['commands']>], TPath> : T extends AnyPadroneCommand ? PickCommandByName<[T], TPath> : never;
|
|
600
174
|
//#endregion
|
|
601
|
-
export {
|
|
175
|
+
export { ActionError, type AnyPadroneBuilder, type AnyPadroneCommand, type AnyPadroneProgram, type AsyncPadroneSchema, ConfigError, type HelpInfo, type InferArgsInput, type InferArgsOutput, type InferCommand, type InteractiveMode, type InteractivePromptConfig, type PadroneActionContext, type PadroneBuilder, type PadroneCommand, type PadroneCommandResult, PadroneError, type PadroneErrorOptions, type PadroneParseResult, type PadronePlugin, type PadroneProgram, type PadroneRuntime, type PadroneSchema, REPL_SIGINT, RoutingError, type UpdateCheckConfig, ValidationError, type WrapConfig, type WrapResult, asyncSchema, buildReplCompleter, createPadrone };
|
|
602
176
|
//# sourceMappingURL=index.d.mts.map
|