padrone 1.4.0 → 1.6.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 +115 -0
- package/README.md +108 -283
- package/dist/args-Cnq0nwSM.mjs +272 -0
- package/dist/args-Cnq0nwSM.mjs.map +1 -0
- package/dist/codegen/index.d.mts +28 -3
- package/dist/codegen/index.d.mts.map +1 -1
- package/dist/codegen/index.mjs +169 -19
- package/dist/codegen/index.mjs.map +1 -1
- package/dist/commands-B_gufyR9.mjs +514 -0
- package/dist/commands-B_gufyR9.mjs.map +1 -0
- package/dist/{completion.mjs → completion-BEuflbDO.mjs} +86 -108
- package/dist/completion-BEuflbDO.mjs.map +1 -0
- package/dist/docs/index.d.mts +22 -2
- package/dist/docs/index.d.mts.map +1 -1
- package/dist/docs/index.mjs +92 -7
- package/dist/docs/index.mjs.map +1 -1
- package/dist/errors-CL63UOzt.mjs +137 -0
- package/dist/errors-CL63UOzt.mjs.map +1 -0
- package/dist/{formatter-ClUK5hcQ.d.mts → formatter-DrvhDMrq.d.mts} +35 -6
- package/dist/formatter-DrvhDMrq.d.mts.map +1 -0
- package/dist/help-B5Kk83of.mjs +849 -0
- package/dist/help-B5Kk83of.mjs.map +1 -0
- package/dist/index-BaU3X6dY.d.mts +1178 -0
- package/dist/index-BaU3X6dY.d.mts.map +1 -0
- package/dist/index.d.mts +763 -36
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3608 -1534
- package/dist/index.mjs.map +1 -1
- package/dist/mcp-BM-d0nZi.mjs +377 -0
- package/dist/mcp-BM-d0nZi.mjs.map +1 -0
- package/dist/serve-Bk0JUlCj.mjs +402 -0
- package/dist/serve-Bk0JUlCj.mjs.map +1 -0
- package/dist/stream-DC4H8YTx.mjs +77 -0
- package/dist/stream-DC4H8YTx.mjs.map +1 -0
- package/dist/test.d.mts +5 -8
- package/dist/test.d.mts.map +1 -1
- package/dist/test.mjs +5 -27
- package/dist/test.mjs.map +1 -1
- package/dist/{update-check-EbNDkzyV.mjs → update-check-CZ2VqjnV.mjs} +16 -17
- package/dist/update-check-CZ2VqjnV.mjs.map +1 -0
- package/dist/zod.d.mts +32 -0
- package/dist/zod.d.mts.map +1 -0
- package/dist/zod.mjs +50 -0
- package/dist/zod.mjs.map +1 -0
- package/package.json +20 -9
- package/src/cli/completions.ts +14 -11
- package/src/cli/docs.ts +13 -16
- package/src/cli/doctor.ts +213 -24
- package/src/cli/index.ts +28 -82
- package/src/cli/init.ts +12 -10
- package/src/cli/link.ts +22 -18
- package/src/cli/wrap.ts +14 -11
- package/src/codegen/discovery.ts +80 -28
- package/src/codegen/index.ts +2 -1
- package/src/codegen/parsers/bash.ts +179 -0
- package/src/codegen/schema-to-code.ts +2 -1
- package/src/core/args.ts +296 -0
- package/src/core/commands.ts +373 -0
- package/src/core/create.ts +268 -0
- package/src/{runtime.ts → core/default-runtime.ts} +70 -135
- package/src/{errors.ts → core/errors.ts} +22 -0
- package/src/core/exec.ts +259 -0
- package/src/core/interceptors.ts +302 -0
- package/src/{parse.ts → core/parse.ts} +36 -89
- package/src/core/program-methods.ts +301 -0
- package/src/core/results.ts +229 -0
- package/src/core/runtime.ts +246 -0
- package/src/core/validate.ts +247 -0
- package/src/docs/index.ts +124 -11
- package/src/extension/auto-output.ts +95 -0
- package/src/extension/color.ts +38 -0
- package/src/extension/completion.ts +49 -0
- package/src/extension/config.ts +262 -0
- package/src/extension/env.ts +101 -0
- package/src/extension/help.ts +192 -0
- package/src/extension/index.ts +43 -0
- package/src/extension/ink.ts +93 -0
- package/src/extension/interactive.ts +106 -0
- package/src/extension/logger.ts +214 -0
- package/src/extension/man.ts +51 -0
- package/src/extension/mcp.ts +52 -0
- package/src/extension/progress-renderer.ts +338 -0
- package/src/extension/progress.ts +299 -0
- package/src/extension/repl.ts +94 -0
- package/src/extension/serve.ts +48 -0
- package/src/extension/signal.ts +87 -0
- package/src/extension/stdin.ts +62 -0
- package/src/extension/suggestions.ts +114 -0
- package/src/extension/timing.ts +81 -0
- package/src/extension/tracing.ts +175 -0
- package/src/extension/update-check.ts +77 -0
- package/src/extension/utils.ts +51 -0
- package/src/extension/version.ts +63 -0
- package/src/{completion.ts → feature/completion.ts} +130 -57
- package/src/{interactive.ts → feature/interactive.ts} +47 -6
- package/src/feature/mcp.ts +387 -0
- package/src/{repl-loop.ts → feature/repl-loop.ts} +26 -16
- package/src/feature/serve.ts +438 -0
- package/src/feature/test.ts +262 -0
- package/src/{update-check.ts → feature/update-check.ts} +16 -16
- package/src/{wrap.ts → feature/wrap.ts} +27 -27
- package/src/index.ts +120 -11
- package/src/output/colorizer.ts +154 -0
- package/src/{formatter.ts → output/formatter.ts} +281 -135
- package/src/{help.ts → output/help.ts} +62 -15
- package/src/{zod.d.ts → schema/zod.d.ts} +1 -1
- package/src/schema/zod.ts +50 -0
- package/src/test.ts +2 -285
- package/src/types/args-meta.ts +151 -0
- package/src/types/builder.ts +697 -0
- package/src/types/command.ts +157 -0
- package/src/types/index.ts +59 -0
- package/src/types/interceptor.ts +296 -0
- package/src/types/preferences.ts +83 -0
- package/src/types/result.ts +71 -0
- package/src/types/schema.ts +19 -0
- package/src/util/dotenv.ts +244 -0
- package/src/{shell-utils.ts → util/shell-utils.ts} +26 -9
- package/src/util/stream.ts +101 -0
- package/src/{type-helpers.ts → util/type-helpers.ts} +23 -16
- package/src/{type-utils.ts → util/type-utils.ts} +99 -37
- package/src/util/utils.ts +51 -0
- package/src/zod.ts +1 -0
- package/dist/args-CVDbyyzG.mjs +0 -199
- package/dist/args-CVDbyyzG.mjs.map +0 -1
- package/dist/chunk-y_GBKt04.mjs +0 -5
- package/dist/completion.d.mts +0 -64
- package/dist/completion.d.mts.map +0 -1
- package/dist/completion.mjs.map +0 -1
- package/dist/formatter-ClUK5hcQ.d.mts.map +0 -1
- package/dist/help-CcBe91bV.mjs +0 -1254
- package/dist/help-CcBe91bV.mjs.map +0 -1
- package/dist/types-DjIdJN5G.d.mts +0 -1059
- package/dist/types-DjIdJN5G.d.mts.map +0 -1
- package/dist/update-check-EbNDkzyV.mjs.map +0 -1
- package/src/args.ts +0 -461
- package/src/colorizer.ts +0 -41
- package/src/command-utils.ts +0 -532
- package/src/create.ts +0 -1477
- package/src/types.ts +0 -1109
- package/src/utils.ts +0 -140
package/src/types.ts
DELETED
|
@@ -1,1109 +0,0 @@
|
|
|
1
|
-
import type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
import type { Tool } from 'ai';
|
|
3
|
-
import type { PadroneArgsSchemaMeta } from './args.ts';
|
|
4
|
-
import type { HelpPreferences } from './help.ts';
|
|
5
|
-
import type { PadroneRuntime, ResolvedPadroneRuntime } from './runtime.ts';
|
|
6
|
-
import type {
|
|
7
|
-
FindDirectChild,
|
|
8
|
-
FlattenCommands,
|
|
9
|
-
FullCommandName,
|
|
10
|
-
IsGeneric,
|
|
11
|
-
MaybePromise,
|
|
12
|
-
OrAsync,
|
|
13
|
-
OrAsyncMeta,
|
|
14
|
-
PickCommandByName,
|
|
15
|
-
PickCommandByPossibleCommands,
|
|
16
|
-
PossibleCommands,
|
|
17
|
-
RepathCommands,
|
|
18
|
-
ReplaceOrAppendCommand,
|
|
19
|
-
SafeString,
|
|
20
|
-
} from './type-utils.ts';
|
|
21
|
-
import type { UpdateCheckConfig } from './update-check.ts';
|
|
22
|
-
import type { WrapConfig, WrapResult } from './wrap.ts';
|
|
23
|
-
|
|
24
|
-
type UnknownRecord = Record<string, unknown>;
|
|
25
|
-
type EmptyRecord = Record<string, never>;
|
|
26
|
-
type DefaultArgs = UnknownRecord | void;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Context object passed as the second argument to command action handlers.
|
|
30
|
-
* Contains the resolved runtime, the executing command, and the program instance.
|
|
31
|
-
*/
|
|
32
|
-
export type PadroneActionContext = {
|
|
33
|
-
/** The resolved runtime for this command (I/O, env, config, etc.). */
|
|
34
|
-
runtime: ResolvedPadroneRuntime;
|
|
35
|
-
/** The command being executed. */
|
|
36
|
-
command: AnyPadroneCommand;
|
|
37
|
-
/** The root program instance. */
|
|
38
|
-
program: AnyPadroneProgram;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* A schema that supports both validation (StandardSchemaV1) and JSON schema generation (StandardJSONSchemaV1).
|
|
43
|
-
* This is the type required for command arguments in Padrone.
|
|
44
|
-
*/
|
|
45
|
-
export type PadroneSchema<Input = unknown, Output = Input> = StandardSchemaV1<Input, Output> & StandardJSONSchemaV1<Input, Output>;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* A schema branded as async. When passed to `.arguments()`, `.configFile()`, or `.env()`,
|
|
49
|
-
* the command is automatically marked as async, causing `parse()` and `cli()` to return Promises.
|
|
50
|
-
*
|
|
51
|
-
* Use the `asyncSchema()` helper to brand an existing schema:
|
|
52
|
-
* ```ts
|
|
53
|
-
* import { asyncSchema } from 'padrone';
|
|
54
|
-
* const schema = asyncSchema(z.object({ name: z.string() }).check(async (v) => { ... }));
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export type AsyncPadroneSchema<Input = unknown, Output = Input> = PadroneSchema<Input, Output> & { '~async': true };
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Helper type to set aliases on a command type.
|
|
61
|
-
* Uses intersection to override just the aliases while preserving all other type information.
|
|
62
|
-
*/
|
|
63
|
-
type WithAliases<TCommand extends AnyPadroneCommand, TAliases extends string[]> = Omit<TCommand, 'aliases' | '~types'> & {
|
|
64
|
-
aliases?: TAliases;
|
|
65
|
-
'~types': Omit<TCommand['~types'], 'aliases'> & { aliases: TAliases };
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Resolves aliases for a command override: if new aliases are provided (non-empty), use them;
|
|
70
|
-
* otherwise, preserve the existing command's aliases.
|
|
71
|
-
*/
|
|
72
|
-
type ResolvedAliases<
|
|
73
|
-
TCommands extends [...AnyPadroneCommand[]],
|
|
74
|
-
TNameNested extends string,
|
|
75
|
-
TAliases extends string[],
|
|
76
|
-
> = TAliases extends []
|
|
77
|
-
? FindDirectChild<TCommands, TNameNested> extends infer E extends AnyPadroneCommand
|
|
78
|
-
? E['~types']['aliases']
|
|
79
|
-
: []
|
|
80
|
-
: TAliases;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Resolves the initial builder type for a `.command()` call.
|
|
84
|
-
* If TNameNested already exists in TCommands, the builder starts pre-populated with that command's types.
|
|
85
|
-
* Otherwise, a fresh builder with default types is used.
|
|
86
|
-
*/
|
|
87
|
-
type InitialCommandBuilder<
|
|
88
|
-
TProgramName extends string,
|
|
89
|
-
TNameNested extends string,
|
|
90
|
-
TParentPath extends string,
|
|
91
|
-
TParentArgs extends PadroneSchema,
|
|
92
|
-
TCommands extends [...AnyPadroneCommand[]],
|
|
93
|
-
> = [FindDirectChild<TCommands, TNameNested>] extends [never]
|
|
94
|
-
? PadroneBuilder<
|
|
95
|
-
TProgramName,
|
|
96
|
-
TNameNested,
|
|
97
|
-
TParentPath,
|
|
98
|
-
PadroneSchema<void>,
|
|
99
|
-
void,
|
|
100
|
-
[],
|
|
101
|
-
TParentArgs,
|
|
102
|
-
PadroneSchema<void>,
|
|
103
|
-
PadroneSchema<void>,
|
|
104
|
-
false
|
|
105
|
-
>
|
|
106
|
-
: FindDirectChild<TCommands, TNameNested> extends infer E extends AnyPadroneCommand
|
|
107
|
-
? PadroneBuilder<
|
|
108
|
-
TProgramName,
|
|
109
|
-
TNameNested,
|
|
110
|
-
TParentPath,
|
|
111
|
-
E['~types']['argsSchema'],
|
|
112
|
-
E['~types']['result'],
|
|
113
|
-
E['~types']['commands'],
|
|
114
|
-
TParentArgs,
|
|
115
|
-
E['~types']['configSchema'],
|
|
116
|
-
E['~types']['envSchema'],
|
|
117
|
-
E['~types']['async']
|
|
118
|
-
>
|
|
119
|
-
: PadroneBuilder<
|
|
120
|
-
TProgramName,
|
|
121
|
-
TNameNested,
|
|
122
|
-
TParentPath,
|
|
123
|
-
PadroneSchema<void>,
|
|
124
|
-
void,
|
|
125
|
-
[],
|
|
126
|
-
TParentArgs,
|
|
127
|
-
PadroneSchema<void>,
|
|
128
|
-
PadroneSchema<void>,
|
|
129
|
-
false
|
|
130
|
-
>;
|
|
131
|
-
|
|
132
|
-
export type AnyPadroneBuilder = InitialCommandBuilder<string, string, string, any, [...AnyPadroneCommand[]]>;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Like InitialCommandBuilder but uses `any` for args/config/env in the fresh case.
|
|
136
|
-
* Used as the default for TBuilder when no builderFn is provided.
|
|
137
|
-
*/
|
|
138
|
-
type DefaultCommandBuilder<
|
|
139
|
-
TProgramName extends string,
|
|
140
|
-
TNameNested extends string,
|
|
141
|
-
TParentPath extends string,
|
|
142
|
-
TParentArgs extends PadroneSchema,
|
|
143
|
-
TCommands extends [...AnyPadroneCommand[]],
|
|
144
|
-
> = [FindDirectChild<TCommands, TNameNested>] extends [never]
|
|
145
|
-
? PadroneBuilder<TProgramName, TNameNested, TParentPath, any, void, [], TParentArgs, any, any, false>
|
|
146
|
-
: FindDirectChild<TCommands, TNameNested> extends infer E extends AnyPadroneCommand
|
|
147
|
-
? PadroneBuilder<
|
|
148
|
-
TProgramName,
|
|
149
|
-
TNameNested,
|
|
150
|
-
TParentPath,
|
|
151
|
-
E['~types']['argsSchema'],
|
|
152
|
-
E['~types']['result'],
|
|
153
|
-
E['~types']['commands'],
|
|
154
|
-
TParentArgs,
|
|
155
|
-
E['~types']['configSchema'],
|
|
156
|
-
E['~types']['envSchema'],
|
|
157
|
-
E['~types']['async']
|
|
158
|
-
>
|
|
159
|
-
: PadroneBuilder<TProgramName, TNameNested, TParentPath, any, void, [], TParentArgs, any, any, false>;
|
|
160
|
-
|
|
161
|
-
export type PadroneCommand<
|
|
162
|
-
TName extends string = string,
|
|
163
|
-
TParentName extends string = '',
|
|
164
|
-
TArgs extends PadroneSchema = PadroneSchema<DefaultArgs>,
|
|
165
|
-
TRes = void,
|
|
166
|
-
TCommands extends [...AnyPadroneCommand[]] = [],
|
|
167
|
-
TAliases extends string[] = string[],
|
|
168
|
-
TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = PadroneSchema<void>,
|
|
169
|
-
TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = PadroneSchema<void>,
|
|
170
|
-
TAsync extends boolean = false,
|
|
171
|
-
> = {
|
|
172
|
-
name: TName;
|
|
173
|
-
path: FullCommandName<TName, TParentName>;
|
|
174
|
-
title?: string;
|
|
175
|
-
description?: string;
|
|
176
|
-
version?: string;
|
|
177
|
-
/** Alternative names that can be used to invoke this command. Derived from the names passed to command(). */
|
|
178
|
-
aliases?: TAliases;
|
|
179
|
-
deprecated?: boolean | string;
|
|
180
|
-
hidden?: boolean;
|
|
181
|
-
needsApproval?: boolean | ((args: TArgs) => Promise<boolean> | boolean);
|
|
182
|
-
autoOutput?: boolean;
|
|
183
|
-
argsSchema?: TArgs;
|
|
184
|
-
configSchema?: TConfig;
|
|
185
|
-
envSchema?: TEnv;
|
|
186
|
-
meta?: GetArgsMeta<TArgs>;
|
|
187
|
-
action?: (args: StandardSchemaV1.InferOutput<TArgs>, ctx: PadroneActionContext) => TRes;
|
|
188
|
-
/** List of possible config file names to search for. */
|
|
189
|
-
configFiles?: string[];
|
|
190
|
-
/** Runtime flag indicating this command uses async validation. Set by `.async()` or `asyncSchema()`. */
|
|
191
|
-
isAsync?: boolean;
|
|
192
|
-
/** Runtime configuration for I/O abstraction. */
|
|
193
|
-
runtime?: PadroneRuntime;
|
|
194
|
-
|
|
195
|
-
/** Plugins registered on this command. Collected from the parent chain at execution time. */
|
|
196
|
-
plugins?: PadronePlugin[];
|
|
197
|
-
|
|
198
|
-
/** Update check configuration. Only used on the root program. */
|
|
199
|
-
updateCheck?: UpdateCheckConfig;
|
|
200
|
-
|
|
201
|
-
parent?: AnyPadroneCommand;
|
|
202
|
-
commands?: TCommands;
|
|
203
|
-
|
|
204
|
-
/** @deprecated Internal use only */
|
|
205
|
-
'~types': {
|
|
206
|
-
name: TName;
|
|
207
|
-
parentName: TParentName;
|
|
208
|
-
path: FullCommandName<TName, TParentName>;
|
|
209
|
-
aliases: TAliases;
|
|
210
|
-
argsSchema: TArgs;
|
|
211
|
-
argsInput: StandardSchemaV1.InferInput<TArgs>;
|
|
212
|
-
argsOutput: StandardSchemaV1.InferOutput<TArgs>;
|
|
213
|
-
result: TRes;
|
|
214
|
-
commands: TCommands;
|
|
215
|
-
configSchema: TConfig;
|
|
216
|
-
envSchema: TEnv;
|
|
217
|
-
async: TAsync;
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
export type AnyPadroneCommand = PadroneCommand<string, any, any, any, [...AnyPadroneCommand[]], string[], any, any, any>;
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Base type for extracting command information from builder or program.
|
|
225
|
-
* Both PadroneBuilder and PadroneProgram share this structure.
|
|
226
|
-
*/
|
|
227
|
-
type CommandTypesBase = {
|
|
228
|
-
'~types': {
|
|
229
|
-
command: AnyPadroneCommand;
|
|
230
|
-
};
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Configuration for a command.
|
|
235
|
-
*/
|
|
236
|
-
export type PadroneCommandConfig = {
|
|
237
|
-
/** A short title for the command, displayed in help. */
|
|
238
|
-
title?: string;
|
|
239
|
-
/** A longer description of what the command does. */
|
|
240
|
-
description?: string;
|
|
241
|
-
/** The version of the command. */
|
|
242
|
-
version?: string;
|
|
243
|
-
/** Whether the command is deprecated, or a message explaining the deprecation. */
|
|
244
|
-
deprecated?: boolean | string;
|
|
245
|
-
/** Whether the command should be hidden from help output. */
|
|
246
|
-
hidden?: boolean;
|
|
247
|
-
/**
|
|
248
|
-
* Automatically write this command's return value to output in CLI/eval/REPL mode.
|
|
249
|
-
* Overrides the `autoOutput` setting in eval/cli preferences for this command.
|
|
250
|
-
* See `PadroneEvalPreferences.autoOutput` for serialization details.
|
|
251
|
-
*/
|
|
252
|
-
autoOutput?: boolean;
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Conditional type that returns either PadroneBuilder or PadroneProgram based on TReturn.
|
|
257
|
-
* Used to avoid repetition in PadroneBuilderMethods return types.
|
|
258
|
-
*/
|
|
259
|
-
type BuilderOrProgram<
|
|
260
|
-
TReturn extends 'builder' | 'program',
|
|
261
|
-
TProgramName extends string,
|
|
262
|
-
TName extends string,
|
|
263
|
-
TParentName extends string,
|
|
264
|
-
TArgs extends PadroneSchema,
|
|
265
|
-
TRes,
|
|
266
|
-
TCommands extends [...AnyPadroneCommand[]],
|
|
267
|
-
TParentArgs extends PadroneSchema,
|
|
268
|
-
TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>>,
|
|
269
|
-
TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>>,
|
|
270
|
-
TAsync extends boolean,
|
|
271
|
-
> = TReturn extends 'builder'
|
|
272
|
-
? PadroneBuilder<TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync>
|
|
273
|
-
: PadroneProgram<TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync>;
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Base builder methods shared between PadroneBuilder and PadroneProgram.
|
|
277
|
-
* These methods are used for defining command structure (arguments, config, env, action, subcommands).
|
|
278
|
-
*/
|
|
279
|
-
export type PadroneBuilderMethods<
|
|
280
|
-
TProgramName extends string,
|
|
281
|
-
TName extends string,
|
|
282
|
-
TParentName extends string,
|
|
283
|
-
TArgs extends PadroneSchema,
|
|
284
|
-
TRes,
|
|
285
|
-
TCommands extends [...AnyPadroneCommand[]],
|
|
286
|
-
TParentArgs extends PadroneSchema,
|
|
287
|
-
TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>>,
|
|
288
|
-
TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>>,
|
|
289
|
-
TAsync extends boolean,
|
|
290
|
-
/** The return type for builder methods - either PadroneBuilder or PadroneProgram */
|
|
291
|
-
TReturn extends 'builder' | 'program',
|
|
292
|
-
> = {
|
|
293
|
-
/**
|
|
294
|
-
* Enables automatic update checking against a package registry.
|
|
295
|
-
* When enabled, the program checks for a newer version in the background
|
|
296
|
-
* and displays a notification after command output if an update is available.
|
|
297
|
-
*
|
|
298
|
-
* - Non-blocking: check runs in background, never delays command execution.
|
|
299
|
-
* - Non-intrusive: shows a one-line notice after command output, not before.
|
|
300
|
-
* - Respects CI: disabled when `CI=true` or non-TTY.
|
|
301
|
-
* - Respects user preference: `--no-update-check` flag or env var.
|
|
302
|
-
* - Caches last check timestamp to avoid hitting the registry on every invocation.
|
|
303
|
-
*
|
|
304
|
-
* @example
|
|
305
|
-
* ```ts
|
|
306
|
-
* createPadrone('myapp')
|
|
307
|
-
* .version('1.2.3')
|
|
308
|
-
* .updateCheck({
|
|
309
|
-
* registry: 'npm', // or custom URL
|
|
310
|
-
* interval: '1d', // check at most once per day
|
|
311
|
-
* cache: '~/.myapp-update' // where to store last check
|
|
312
|
-
* })
|
|
313
|
-
* ```
|
|
314
|
-
*/
|
|
315
|
-
updateCheck: (
|
|
316
|
-
config?: UpdateCheckConfig,
|
|
317
|
-
) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync>;
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Registers a plugin that intercepts command execution phases (parse, validate, execute).
|
|
321
|
-
* Plugins are applied in order: first registered = outermost wrapper (runs first before `next()`).
|
|
322
|
-
* Use `plugin.order` for explicit ordering (lower = outermost).
|
|
323
|
-
*
|
|
324
|
-
* On the program, parse/validate/execute plugins all apply.
|
|
325
|
-
* On subcommands, only validate and execute plugins apply (parse is handled by the root program).
|
|
326
|
-
*/
|
|
327
|
-
use: (
|
|
328
|
-
plugin: PadronePlugin,
|
|
329
|
-
) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync>;
|
|
330
|
-
|
|
331
|
-
configure: (
|
|
332
|
-
config: PadroneCommandConfig,
|
|
333
|
-
) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync>;
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Configures the runtime adapter for I/O abstraction.
|
|
337
|
-
* Allows the CLI framework to work outside of a terminal (e.g., web UIs, chat interfaces, testing).
|
|
338
|
-
* Unspecified fields fall back to the Node.js/Bun defaults.
|
|
339
|
-
*
|
|
340
|
-
* @example
|
|
341
|
-
* ```ts
|
|
342
|
-
* .runtime({
|
|
343
|
-
* output: (text) => panel.append(text),
|
|
344
|
-
* error: (text) => panel.appendError(text),
|
|
345
|
-
* format: 'html',
|
|
346
|
-
* })
|
|
347
|
-
* ```
|
|
348
|
-
*/
|
|
349
|
-
runtime: (
|
|
350
|
-
runtime: PadroneRuntime,
|
|
351
|
-
) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync>;
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Explicitly marks this command as using async validation.
|
|
355
|
-
* When a command is async, `parse()` and `cli()` return Promises.
|
|
356
|
-
*
|
|
357
|
-
* This is an alternative to using `asyncSchema()` on individual schemas.
|
|
358
|
-
* Use this when your schema has async refinements but you don't want to
|
|
359
|
-
* (or can't) brand the schema itself.
|
|
360
|
-
*
|
|
361
|
-
* @example
|
|
362
|
-
* ```ts
|
|
363
|
-
* .arguments(z.object({ name: z.string() }).check(async (v) => { ... }))
|
|
364
|
-
* .async()
|
|
365
|
-
* .action((args) => { ... })
|
|
366
|
-
* ```
|
|
367
|
-
*/
|
|
368
|
-
async: () => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, true>;
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Defines the arguments schema for the command, including positional arguments.
|
|
372
|
-
* Can accept either a schema directly or a function that takes parent args schema as a base and returns a schema.
|
|
373
|
-
* Use the `positional` array in meta to specify which arguments are positional args.
|
|
374
|
-
* Use '...name' prefix for variadic (rest) arguments, matching JS/TS rest syntax.
|
|
375
|
-
*
|
|
376
|
-
* @example
|
|
377
|
-
* ```ts
|
|
378
|
-
* // Direct schema
|
|
379
|
-
* .arguments(z.object({
|
|
380
|
-
* source: z.string(),
|
|
381
|
-
* files: z.string().array(),
|
|
382
|
-
* dest: z.string(),
|
|
383
|
-
* recursive: z.boolean().default(false),
|
|
384
|
-
* }), {
|
|
385
|
-
* positional: ['source', '...files', 'dest'],
|
|
386
|
-
* })
|
|
387
|
-
* ```
|
|
388
|
-
*
|
|
389
|
-
* @example
|
|
390
|
-
* ```ts
|
|
391
|
-
* // Function-based schema extending parent arguments
|
|
392
|
-
* .arguments((parentArgs) => {
|
|
393
|
-
* return z.object({
|
|
394
|
-
* ...parentArgs.shape,
|
|
395
|
-
* verbose: z.boolean().default(false),
|
|
396
|
-
* });
|
|
397
|
-
* })
|
|
398
|
-
* ```
|
|
399
|
-
*/
|
|
400
|
-
arguments: <TNewArgs extends PadroneSchema = PadroneSchema<void>, TMeta extends GetArgsMeta<TNewArgs> = GetArgsMeta<TNewArgs>>(
|
|
401
|
-
schema?: TNewArgs | ((parentSchema: TParentArgs) => TNewArgs),
|
|
402
|
-
meta?: TMeta,
|
|
403
|
-
) => BuilderOrProgram<
|
|
404
|
-
TReturn,
|
|
405
|
-
TProgramName,
|
|
406
|
-
TName,
|
|
407
|
-
TParentName,
|
|
408
|
-
TNewArgs,
|
|
409
|
-
TRes,
|
|
410
|
-
TCommands,
|
|
411
|
-
TParentArgs,
|
|
412
|
-
TConfig,
|
|
413
|
-
TEnv,
|
|
414
|
-
OrAsyncMeta<OrAsync<TAsync, TNewArgs>, TMeta>
|
|
415
|
-
>;
|
|
416
|
-
|
|
417
|
-
/**
|
|
418
|
-
* Configures config file path(s) and schema for parsing config files.
|
|
419
|
-
* @example
|
|
420
|
-
* ```ts
|
|
421
|
-
* .configFile('config.json', z.object({ port: z.number() }))
|
|
422
|
-
* ```
|
|
423
|
-
*/
|
|
424
|
-
configFile: <TNewConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = TArgs>(
|
|
425
|
-
file: string | string[] | undefined,
|
|
426
|
-
schema?: TNewConfig | ((argsSchema: TArgs) => TNewConfig),
|
|
427
|
-
) => BuilderOrProgram<
|
|
428
|
-
TReturn,
|
|
429
|
-
TProgramName,
|
|
430
|
-
TName,
|
|
431
|
-
TParentName,
|
|
432
|
-
TArgs,
|
|
433
|
-
TRes,
|
|
434
|
-
TCommands,
|
|
435
|
-
TParentArgs,
|
|
436
|
-
TNewConfig,
|
|
437
|
-
TEnv,
|
|
438
|
-
OrAsync<TAsync, TNewConfig>
|
|
439
|
-
>;
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Configures environment variable schema for parsing env vars into arguments.
|
|
443
|
-
* The schema should transform environment variables (typically SCREAMING_SNAKE_CASE)
|
|
444
|
-
* into the argument names used by the command.
|
|
445
|
-
* @example
|
|
446
|
-
* ```ts
|
|
447
|
-
* .env(z.object({ MY_APP_PORT: z.coerce.number() }).transform(e => ({ port: e.MY_APP_PORT })))
|
|
448
|
-
* ```
|
|
449
|
-
*/
|
|
450
|
-
env: <TNewEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = TArgs>(
|
|
451
|
-
schema: TNewEnv | ((argsSchema: TArgs) => TNewEnv),
|
|
452
|
-
) => BuilderOrProgram<
|
|
453
|
-
TReturn,
|
|
454
|
-
TProgramName,
|
|
455
|
-
TName,
|
|
456
|
-
TParentName,
|
|
457
|
-
TArgs,
|
|
458
|
-
TRes,
|
|
459
|
-
TCommands,
|
|
460
|
-
TParentArgs,
|
|
461
|
-
TConfig,
|
|
462
|
-
TNewEnv,
|
|
463
|
-
OrAsync<TAsync, TNewEnv>
|
|
464
|
-
>;
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* Defines the handler function to be executed when the command is run.
|
|
468
|
-
* When overriding an existing command, the previous handler is passed as the third `base` parameter.
|
|
469
|
-
*/
|
|
470
|
-
action: <TNewRes>(
|
|
471
|
-
handler?: (
|
|
472
|
-
args: StandardSchemaV1.InferOutput<TArgs>,
|
|
473
|
-
ctx: PadroneActionContext,
|
|
474
|
-
base: (args: StandardSchemaV1.InferOutput<TArgs>, ctx: PadroneActionContext) => TRes,
|
|
475
|
-
) => TNewRes,
|
|
476
|
-
) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TNewRes, TCommands, TParentArgs, TConfig, TEnv, TAsync>;
|
|
477
|
-
|
|
478
|
-
/**
|
|
479
|
-
* Wraps an external CLI tool with optional schema transformation.
|
|
480
|
-
* The config can include a schema that transforms command arguments to external CLI arguments.
|
|
481
|
-
*
|
|
482
|
-
* @example
|
|
483
|
-
* ```ts
|
|
484
|
-
* // No transformation - pass arguments as-is
|
|
485
|
-
* .arguments(z.object({
|
|
486
|
-
* message: z.string(),
|
|
487
|
-
* }))
|
|
488
|
-
* .wrap({
|
|
489
|
-
* command: 'echo',
|
|
490
|
-
* })
|
|
491
|
-
* ```
|
|
492
|
-
*
|
|
493
|
-
* @example
|
|
494
|
-
* ```ts
|
|
495
|
-
* // With transformation schema
|
|
496
|
-
* .arguments(z.object({
|
|
497
|
-
* message: z.string(),
|
|
498
|
-
* all: z.boolean().optional(),
|
|
499
|
-
* }), {
|
|
500
|
-
* positional: ['message'],
|
|
501
|
-
* })
|
|
502
|
-
* .wrap({
|
|
503
|
-
* command: 'git',
|
|
504
|
-
* args: ['commit'],
|
|
505
|
-
* positional: ['m'],
|
|
506
|
-
* schema: z.object({
|
|
507
|
-
* message: z.string(),
|
|
508
|
-
* all: z.boolean().optional(),
|
|
509
|
-
* }).transform(args => ({
|
|
510
|
-
* m: args.message,
|
|
511
|
-
* a: args.all,
|
|
512
|
-
* })),
|
|
513
|
-
* })
|
|
514
|
-
* ```
|
|
515
|
-
*
|
|
516
|
-
* @example
|
|
517
|
-
* ```ts
|
|
518
|
-
* // Using function-based schema for type inference
|
|
519
|
-
* .arguments(z.object({
|
|
520
|
-
* image: z.string(),
|
|
521
|
-
* detach: z.boolean().optional(),
|
|
522
|
-
* }))
|
|
523
|
-
* .wrap({
|
|
524
|
-
* command: 'docker',
|
|
525
|
-
* args: ['run'],
|
|
526
|
-
* positional: ['image'],
|
|
527
|
-
* schema: (schema) => schema.transform(args => ({
|
|
528
|
-
* d: args.detach,
|
|
529
|
-
* image: args.image,
|
|
530
|
-
* })),
|
|
531
|
-
* })
|
|
532
|
-
* ```
|
|
533
|
-
*/
|
|
534
|
-
wrap: <TWrapArgs extends PadroneSchema = TArgs>(
|
|
535
|
-
config: WrapConfig<TArgs, TWrapArgs>,
|
|
536
|
-
) => BuilderOrProgram<
|
|
537
|
-
TReturn,
|
|
538
|
-
TProgramName,
|
|
539
|
-
TName,
|
|
540
|
-
TParentName,
|
|
541
|
-
TArgs,
|
|
542
|
-
Promise<WrapResult>,
|
|
543
|
-
TCommands,
|
|
544
|
-
TParentArgs,
|
|
545
|
-
TConfig,
|
|
546
|
-
TEnv,
|
|
547
|
-
TAsync
|
|
548
|
-
>;
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
* Creates or extends a nested command within the current command.
|
|
552
|
-
* If a command with the same name already exists, it is extended:
|
|
553
|
-
* - Configuration is merged (new values override old).
|
|
554
|
-
* - The builder callback receives a builder pre-populated with the existing command's state.
|
|
555
|
-
* - `.action()` receives the previous handler as the third `base` parameter.
|
|
556
|
-
* - `.arguments()` callback receives the existing schema as its parameter.
|
|
557
|
-
* - Subcommands are recursively merged by name.
|
|
558
|
-
*
|
|
559
|
-
* @example
|
|
560
|
-
* ```ts
|
|
561
|
-
* // Fresh command
|
|
562
|
-
* .command('list', (c) => c.action(() => 'list'))
|
|
563
|
-
*
|
|
564
|
-
* // Override — extend an existing command
|
|
565
|
-
* .command('list', (c) => c.action((args, ctx, base) => {
|
|
566
|
-
* const original = base(args, ctx);
|
|
567
|
-
* return `modified: ${original}`;
|
|
568
|
-
* }))
|
|
569
|
-
*
|
|
570
|
-
* // Name with aliases
|
|
571
|
-
* .command(['list', 'ls', 'l'], (c) => c.action(() => 'list'))
|
|
572
|
-
* ```
|
|
573
|
-
*/
|
|
574
|
-
command: <
|
|
575
|
-
TNameNested extends string,
|
|
576
|
-
TAliases extends string[] = [],
|
|
577
|
-
TBuilder extends CommandTypesBase = DefaultCommandBuilder<
|
|
578
|
-
TProgramName,
|
|
579
|
-
TNameNested,
|
|
580
|
-
FullCommandName<TName, TParentName>,
|
|
581
|
-
TArgs,
|
|
582
|
-
TCommands
|
|
583
|
-
>,
|
|
584
|
-
>(
|
|
585
|
-
name: TNameNested | readonly [TNameNested, ...TAliases],
|
|
586
|
-
builderFn?: (
|
|
587
|
-
builder: InitialCommandBuilder<TProgramName, TNameNested, FullCommandName<TName, TParentName>, TArgs, TCommands>,
|
|
588
|
-
) => TBuilder,
|
|
589
|
-
) => BuilderOrProgram<
|
|
590
|
-
TReturn,
|
|
591
|
-
TProgramName,
|
|
592
|
-
TName,
|
|
593
|
-
TParentName,
|
|
594
|
-
TArgs,
|
|
595
|
-
TRes,
|
|
596
|
-
TCommands extends []
|
|
597
|
-
? [WithAliases<TBuilder['~types']['command'], TAliases>]
|
|
598
|
-
: AnyPadroneCommand[] extends TCommands
|
|
599
|
-
? [WithAliases<TBuilder['~types']['command'], TAliases>]
|
|
600
|
-
: ReplaceOrAppendCommand<
|
|
601
|
-
TCommands,
|
|
602
|
-
TNameNested,
|
|
603
|
-
WithAliases<TBuilder['~types']['command'], ResolvedAliases<TCommands, TNameNested, TAliases>>
|
|
604
|
-
>,
|
|
605
|
-
TParentArgs,
|
|
606
|
-
TConfig,
|
|
607
|
-
TEnv,
|
|
608
|
-
TAsync
|
|
609
|
-
>;
|
|
610
|
-
|
|
611
|
-
/**
|
|
612
|
-
* Mounts an existing Padrone program as a subcommand.
|
|
613
|
-
* The program's root-level properties (name, path, parent) are replaced to fit the mount point.
|
|
614
|
-
* All subcommands are recursively re-pathed. Root-level `version` is dropped.
|
|
615
|
-
*
|
|
616
|
-
* @example
|
|
617
|
-
* ```ts
|
|
618
|
-
* const admin = createPadrone('admin')
|
|
619
|
-
* .command('users', (c) => c.action(() => 'users'))
|
|
620
|
-
* .command('roles', (c) => c.action(() => 'roles'));
|
|
621
|
-
*
|
|
622
|
-
* const app = createPadrone('app')
|
|
623
|
-
* .mount('admin', admin)
|
|
624
|
-
* // Now: app admin users, app admin roles
|
|
625
|
-
*
|
|
626
|
-
* // With aliases
|
|
627
|
-
* const app2 = createPadrone('app')
|
|
628
|
-
* .mount(['admin', 'adm'], admin)
|
|
629
|
-
* ```
|
|
630
|
-
*/
|
|
631
|
-
mount: <TNameNested extends string, TAliases extends string[] = [], TProgram extends CommandTypesBase = CommandTypesBase>(
|
|
632
|
-
name: TNameNested | readonly [TNameNested, ...TAliases],
|
|
633
|
-
program: TProgram,
|
|
634
|
-
) => BuilderOrProgram<
|
|
635
|
-
TReturn,
|
|
636
|
-
TProgramName,
|
|
637
|
-
TName,
|
|
638
|
-
TParentName,
|
|
639
|
-
TArgs,
|
|
640
|
-
TRes,
|
|
641
|
-
TCommands extends []
|
|
642
|
-
? [
|
|
643
|
-
WithAliases<
|
|
644
|
-
PadroneCommand<
|
|
645
|
-
TNameNested,
|
|
646
|
-
FullCommandName<TName, TParentName>,
|
|
647
|
-
TProgram['~types']['command']['~types']['argsSchema'],
|
|
648
|
-
TProgram['~types']['command']['~types']['result'],
|
|
649
|
-
RepathCommands<
|
|
650
|
-
TProgram['~types']['command']['~types']['commands'],
|
|
651
|
-
FullCommandName<TNameNested, FullCommandName<TName, TParentName>>
|
|
652
|
-
>,
|
|
653
|
-
[],
|
|
654
|
-
TProgram['~types']['command']['~types']['configSchema'],
|
|
655
|
-
TProgram['~types']['command']['~types']['envSchema'],
|
|
656
|
-
TProgram['~types']['command']['~types']['async']
|
|
657
|
-
>,
|
|
658
|
-
TAliases
|
|
659
|
-
>,
|
|
660
|
-
]
|
|
661
|
-
: AnyPadroneCommand[] extends TCommands
|
|
662
|
-
? [
|
|
663
|
-
WithAliases<
|
|
664
|
-
PadroneCommand<
|
|
665
|
-
TNameNested,
|
|
666
|
-
FullCommandName<TName, TParentName>,
|
|
667
|
-
TProgram['~types']['command']['~types']['argsSchema'],
|
|
668
|
-
TProgram['~types']['command']['~types']['result'],
|
|
669
|
-
RepathCommands<
|
|
670
|
-
TProgram['~types']['command']['~types']['commands'],
|
|
671
|
-
FullCommandName<TNameNested, FullCommandName<TName, TParentName>>
|
|
672
|
-
>,
|
|
673
|
-
[],
|
|
674
|
-
TProgram['~types']['command']['~types']['configSchema'],
|
|
675
|
-
TProgram['~types']['command']['~types']['envSchema'],
|
|
676
|
-
TProgram['~types']['command']['~types']['async']
|
|
677
|
-
>,
|
|
678
|
-
TAliases
|
|
679
|
-
>,
|
|
680
|
-
]
|
|
681
|
-
: ReplaceOrAppendCommand<
|
|
682
|
-
TCommands,
|
|
683
|
-
TNameNested,
|
|
684
|
-
WithAliases<
|
|
685
|
-
PadroneCommand<
|
|
686
|
-
TNameNested,
|
|
687
|
-
FullCommandName<TName, TParentName>,
|
|
688
|
-
TProgram['~types']['command']['~types']['argsSchema'],
|
|
689
|
-
TProgram['~types']['command']['~types']['result'],
|
|
690
|
-
RepathCommands<
|
|
691
|
-
TProgram['~types']['command']['~types']['commands'],
|
|
692
|
-
FullCommandName<TNameNested, FullCommandName<TName, TParentName>>
|
|
693
|
-
>,
|
|
694
|
-
[],
|
|
695
|
-
TProgram['~types']['command']['~types']['configSchema'],
|
|
696
|
-
TProgram['~types']['command']['~types']['envSchema'],
|
|
697
|
-
TProgram['~types']['command']['~types']['async']
|
|
698
|
-
>,
|
|
699
|
-
ResolvedAliases<TCommands, TNameNested, TAliases>
|
|
700
|
-
>
|
|
701
|
-
>,
|
|
702
|
-
TParentArgs,
|
|
703
|
-
TConfig,
|
|
704
|
-
TEnv,
|
|
705
|
-
TAsync
|
|
706
|
-
>;
|
|
707
|
-
|
|
708
|
-
/** @deprecated Internal use only */
|
|
709
|
-
'~types': {
|
|
710
|
-
programName: TProgramName;
|
|
711
|
-
name: TName;
|
|
712
|
-
parentName: TParentName;
|
|
713
|
-
path: FullCommandName<TName, TParentName>;
|
|
714
|
-
aliases: [];
|
|
715
|
-
argsSchema: TArgs;
|
|
716
|
-
result: TRes;
|
|
717
|
-
commands: TCommands;
|
|
718
|
-
async: TAsync;
|
|
719
|
-
command: PadroneCommand<TName, TParentName, TArgs, TRes, TCommands, [], TConfig, TEnv, TAsync>;
|
|
720
|
-
};
|
|
721
|
-
};
|
|
722
|
-
|
|
723
|
-
export type PadroneBuilder<
|
|
724
|
-
TProgramName extends string = '',
|
|
725
|
-
TName extends string = string,
|
|
726
|
-
TParentName extends string = '',
|
|
727
|
-
TArgs extends PadroneSchema = PadroneSchema<DefaultArgs>,
|
|
728
|
-
TRes = void,
|
|
729
|
-
TCommands extends [...AnyPadroneCommand[]] = [],
|
|
730
|
-
TParentArgs extends PadroneSchema = PadroneSchema<void>,
|
|
731
|
-
TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = PadroneSchema<void>,
|
|
732
|
-
TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = PadroneSchema<void>,
|
|
733
|
-
TAsync extends boolean = false,
|
|
734
|
-
> = PadroneBuilderMethods<TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync, 'builder'>;
|
|
735
|
-
|
|
736
|
-
export type PadroneProgram<
|
|
737
|
-
TProgramName extends string = '',
|
|
738
|
-
TName extends string = string,
|
|
739
|
-
TParentName extends string = '',
|
|
740
|
-
TArgs extends PadroneSchema = PadroneSchema<DefaultArgs>,
|
|
741
|
-
TRes = void,
|
|
742
|
-
TCommands extends [...AnyPadroneCommand[]] = [],
|
|
743
|
-
TParentArgs extends PadroneSchema = PadroneSchema<void>,
|
|
744
|
-
TConfig extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = PadroneSchema<void>,
|
|
745
|
-
TEnv extends PadroneSchema<unknown, StandardSchemaV1.InferInput<TArgs>> = PadroneSchema<void>,
|
|
746
|
-
TAsync extends boolean = false,
|
|
747
|
-
> = PadroneBuilderMethods<TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TConfig, TEnv, TAsync, 'program'> & {
|
|
748
|
-
/**
|
|
749
|
-
* Runs a command programmatically by name with provided arguments (including positional args).
|
|
750
|
-
*/
|
|
751
|
-
run: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], true, true>>(
|
|
752
|
-
name: TCommand | SafeString,
|
|
753
|
-
args: NoInfer<GetArguments<'in', PickCommandByName<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>>,
|
|
754
|
-
) => PadroneCommandResult<PickCommandByName<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>;
|
|
755
|
-
|
|
756
|
-
/**
|
|
757
|
-
* Evaluates a command string: parses, validates, and executes.
|
|
758
|
-
* On validation errors, returns a result with issues instead of throwing.
|
|
759
|
-
* This is the method used by `repl()` internally, and the right choice for
|
|
760
|
-
* programmatic invocation, testing, chat interfaces, or any context where
|
|
761
|
-
* you have a command string and want a result — not a process exit.
|
|
762
|
-
*
|
|
763
|
-
* @example
|
|
764
|
-
* ```ts
|
|
765
|
-
* const result = await program.eval('greet --name Alice');
|
|
766
|
-
* if (result.argsResult?.issues) { /* handle validation errors *\/ }
|
|
767
|
-
* ```
|
|
768
|
-
*/
|
|
769
|
-
eval: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], true, true>>(
|
|
770
|
-
input: TCommand | SafeString,
|
|
771
|
-
prefs?: PadroneEvalPreferences,
|
|
772
|
-
) => MaybePromise<
|
|
773
|
-
PadroneCommandResult<PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>,
|
|
774
|
-
PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>['~types']['async']
|
|
775
|
-
>;
|
|
776
|
-
|
|
777
|
-
/**
|
|
778
|
-
* Runs the program as a CLI entry point, parsing `process.argv`.
|
|
779
|
-
* On validation errors, throws and prints help.
|
|
780
|
-
* For programmatic invocation with a command string, use `eval()` instead.
|
|
781
|
-
*/
|
|
782
|
-
cli: (
|
|
783
|
-
prefs?: PadroneCliPreferences<PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>>,
|
|
784
|
-
) => MaybePromise<PadroneCommandResult<FlattenCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>>, TAsync>;
|
|
785
|
-
|
|
786
|
-
/**
|
|
787
|
-
* Parses CLI input (or the provided input string) into command and arguments without executing anything.
|
|
788
|
-
*/
|
|
789
|
-
parse: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], true, false>>(
|
|
790
|
-
input?: TCommand | SafeString,
|
|
791
|
-
) => MaybePromise<
|
|
792
|
-
PadroneParseResult<PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>,
|
|
793
|
-
PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>['~types']['async']
|
|
794
|
-
>;
|
|
795
|
-
|
|
796
|
-
/**
|
|
797
|
-
* Converts command and arguments back into a CLI string.
|
|
798
|
-
*/
|
|
799
|
-
stringify: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], false, true>>(
|
|
800
|
-
command?: TCommand | SafeString,
|
|
801
|
-
args?: GetArguments<'out', PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>,
|
|
802
|
-
) => string;
|
|
803
|
-
|
|
804
|
-
/**
|
|
805
|
-
* Finds a command by name, returning `undefined` if not found.
|
|
806
|
-
*/
|
|
807
|
-
find: <const TFind extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], false, true>>(
|
|
808
|
-
command: TFind | SafeString,
|
|
809
|
-
) => PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TFind> | undefined;
|
|
810
|
-
|
|
811
|
-
/**
|
|
812
|
-
* Generates a type-safe API for invoking commands programmatically.
|
|
813
|
-
*/
|
|
814
|
-
api: () => PadroneAPI<PadroneCommand<'', '', TArgs, TRes, TCommands>>;
|
|
815
|
-
|
|
816
|
-
/**
|
|
817
|
-
* Starts a REPL (Read-Eval-Print Loop) for running commands interactively.
|
|
818
|
-
* Returns an AsyncIterable that yields a `PadroneCommandResult` for each successfully executed command.
|
|
819
|
-
* Errors are printed via `runtime.error()` and the loop continues.
|
|
820
|
-
* The loop ends when the user sends EOF (Ctrl+D), types `.exit`/`.quit`,
|
|
821
|
-
* or presses Ctrl+C twice within 2 seconds.
|
|
822
|
-
*
|
|
823
|
-
* @example
|
|
824
|
-
* ```ts
|
|
825
|
-
* for await (const result of program.repl()) {
|
|
826
|
-
* console.log(result.command.name, result.result);
|
|
827
|
-
* }
|
|
828
|
-
* ```
|
|
829
|
-
*
|
|
830
|
-
* TODO: REPL future enhancements:
|
|
831
|
-
* - History persistence: save/load history across sessions (currently in-memory only)
|
|
832
|
-
* - Middleware/hooks: onBeforeCommand, onAfterCommand, error interceptors (design alongside general middleware system)
|
|
833
|
-
*/
|
|
834
|
-
repl: (
|
|
835
|
-
options?: PadroneReplPreferences<PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>>,
|
|
836
|
-
) => AsyncIterable<PadroneCommandResult<FlattenCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>>>;
|
|
837
|
-
|
|
838
|
-
/**
|
|
839
|
-
* Returns a tool definition that can be passed to AI SDK.
|
|
840
|
-
*/
|
|
841
|
-
tool: () => Tool<{ command: string }>;
|
|
842
|
-
|
|
843
|
-
/**
|
|
844
|
-
* Returns the help information for the program or a specific command.
|
|
845
|
-
*/
|
|
846
|
-
help: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], false, true>>(
|
|
847
|
-
command?: TCommand,
|
|
848
|
-
prefs?: HelpPreferences,
|
|
849
|
-
) => string;
|
|
850
|
-
|
|
851
|
-
/**
|
|
852
|
-
* Generates and returns a shell completion script.
|
|
853
|
-
* If shell is not specified, automatically detects the current shell and provides instructions.
|
|
854
|
-
* @param shell - The shell type (bash, zsh, fish, powershell). If not provided, auto-detects.
|
|
855
|
-
* @returns The shell completion script as a string.
|
|
856
|
-
* @example
|
|
857
|
-
* ```ts
|
|
858
|
-
* // Get bash completion script
|
|
859
|
-
* const bashScript = program.completion('bash');
|
|
860
|
-
*
|
|
861
|
-
* // Auto-detect shell and get completion script with instructions
|
|
862
|
-
* const script = program.completion();
|
|
863
|
-
* ```
|
|
864
|
-
*/
|
|
865
|
-
completion: (shell?: 'bash' | 'zsh' | 'fish' | 'powershell') => Promise<string>;
|
|
866
|
-
};
|
|
867
|
-
|
|
868
|
-
export type AnyPadroneProgram = PadroneProgram<string, string, string, any, any, [...AnyPadroneCommand[]]>;
|
|
869
|
-
|
|
870
|
-
/**
|
|
871
|
-
* Options for `repl()` to customize the REPL session.
|
|
872
|
-
*/
|
|
873
|
-
/** A single spacing value: blank line (`true`), separator string, or an array of these for multiple lines. */
|
|
874
|
-
export type PadroneReplSpacing = boolean | string | (boolean | string)[];
|
|
875
|
-
|
|
876
|
-
export type PadroneReplPreferences<TScope extends string = string> = {
|
|
877
|
-
/** The prompt string displayed before each input, or a function returning it. Defaults to `"<programName>> "`. */
|
|
878
|
-
prompt?: string | (() => string);
|
|
879
|
-
/**
|
|
880
|
-
* A greeting message displayed when the REPL starts.
|
|
881
|
-
* When not provided, defaults to `"Welcome to <name> v<version>"` (or just `"Welcome to <name>"` if no version).
|
|
882
|
-
* Set to `false` to suppress the default greeting entirely.
|
|
883
|
-
*/
|
|
884
|
-
greeting?: string | false;
|
|
885
|
-
/**
|
|
886
|
-
* A hint message displayed below the greeting in dimmed text.
|
|
887
|
-
* When not provided, defaults to `'Type ".help" for more information, ".exit" to quit.'`.
|
|
888
|
-
* Set to `false` to suppress the hint.
|
|
889
|
-
*/
|
|
890
|
-
hint?: string | false;
|
|
891
|
-
/** Initial history entries (most recent last). Arrow keys navigate history in the terminal. */
|
|
892
|
-
history?: string[];
|
|
893
|
-
/** Set to `false` to disable tab completion. Defaults to `true`. */
|
|
894
|
-
completion?: boolean;
|
|
895
|
-
/**
|
|
896
|
-
* Add spacing/separators around each command's output.
|
|
897
|
-
* A spacing value can be:
|
|
898
|
-
* - `true` — blank line
|
|
899
|
-
* - A string — separator line (single char like `'─'` repeats to terminal width, multi-char prints as-is)
|
|
900
|
-
* - An array of the above — multiple lines in order (e.g. `[true, '─']` for blank line then separator)
|
|
901
|
-
*
|
|
902
|
-
* Shorthand applies to both before and after. Use `{ before?, after? }` for independent control.
|
|
903
|
-
*/
|
|
904
|
-
spacing?: PadroneReplSpacing | { before?: PadroneReplSpacing; after?: PadroneReplSpacing };
|
|
905
|
-
/** Prefix each line of command output/error with this string (e.g. `'│ '`, `' '`, `'▎ '`). */
|
|
906
|
-
outputPrefix?: string;
|
|
907
|
-
/**
|
|
908
|
-
* Start the REPL scoped to a command subtree. The scope path is a space-separated command path
|
|
909
|
-
* (e.g. `'db'` or `'db migrate'`). Commands are resolved relative to the scoped command.
|
|
910
|
-
* Users can change scope at runtime with `.scope <subcommand>` and `.scope ..`/`..`.
|
|
911
|
-
*/
|
|
912
|
-
scope?: TScope;
|
|
913
|
-
|
|
914
|
-
/**
|
|
915
|
-
* Automatically write each command's return value to output.
|
|
916
|
-
* See `PadroneEvalPreferences.autoOutput` for details on how values are serialized.
|
|
917
|
-
* Defaults to `true`.
|
|
918
|
-
*/
|
|
919
|
-
autoOutput?: boolean;
|
|
920
|
-
};
|
|
921
|
-
|
|
922
|
-
/**
|
|
923
|
-
* Options that can be passed to `eval()` to control execution behavior.
|
|
924
|
-
*/
|
|
925
|
-
export type PadroneEvalPreferences = {
|
|
926
|
-
/**
|
|
927
|
-
* Controls interactive prompting for this execution.
|
|
928
|
-
* Overrides the runtime's `interactive` setting, but is itself overridden by `--interactive` / `-i` flags.
|
|
929
|
-
*
|
|
930
|
-
* - `undefined`: inherit from runtime (default).
|
|
931
|
-
* - `true`: force prompting for all configured interactive fields, even if values are already provided.
|
|
932
|
-
* - `false`: suppress all interactive prompts.
|
|
933
|
-
*/
|
|
934
|
-
interactive?: boolean;
|
|
935
|
-
|
|
936
|
-
/**
|
|
937
|
-
* Automatically write the command's return value to output.
|
|
938
|
-
*
|
|
939
|
-
* - Values are passed directly to the runtime's `output` function (no stringification).
|
|
940
|
-
* - Promises are awaited before output.
|
|
941
|
-
* - Iterators and async iterators are consumed, outputting each yielded value as it arrives.
|
|
942
|
-
* - `undefined` and `null` results produce no output.
|
|
943
|
-
*
|
|
944
|
-
* Defaults to `true`. Set to `false` to disable.
|
|
945
|
-
*/
|
|
946
|
-
autoOutput?: boolean;
|
|
947
|
-
|
|
948
|
-
/**
|
|
949
|
-
* Override the runtime for this execution.
|
|
950
|
-
* Partial — only the provided fields replace the command's resolved runtime.
|
|
951
|
-
* Useful for capturing output, injecting test doubles, or running in non-terminal contexts (e.g. AI tool calls).
|
|
952
|
-
*/
|
|
953
|
-
runtime?: PadroneRuntime;
|
|
954
|
-
};
|
|
955
|
-
|
|
956
|
-
/**
|
|
957
|
-
* Options that can be passed to `cli()` to control execution behavior.
|
|
958
|
-
*/
|
|
959
|
-
export type PadroneCliPreferences<TScope extends string = string> = PadroneEvalPreferences & {
|
|
960
|
-
/** REPL preferences used when `--repl` flag is passed. Set to `false` to disable the `--repl` flag. */
|
|
961
|
-
repl?: PadroneReplPreferences<TScope> | false;
|
|
962
|
-
};
|
|
963
|
-
|
|
964
|
-
export type PadroneCommandResult<TCommand extends AnyPadroneCommand = AnyPadroneCommand> = PadroneParseResult<TCommand> & {
|
|
965
|
-
result: GetResults<TCommand>;
|
|
966
|
-
};
|
|
967
|
-
|
|
968
|
-
export type PadroneParseResult<TCommand extends AnyPadroneCommand = AnyPadroneCommand> = {
|
|
969
|
-
command: TCommand;
|
|
970
|
-
args?: GetArguments<'out', TCommand>;
|
|
971
|
-
argsResult?: StandardSchemaV1.Result<GetArguments<'out', TCommand>>;
|
|
972
|
-
};
|
|
973
|
-
|
|
974
|
-
export type PadroneAPI<TCommand extends AnyPadroneCommand> = PadroneAPICommand<TCommand> & {
|
|
975
|
-
[K in TCommand['~types']['commands'][number] as K['name']]: PadroneAPI<K>;
|
|
976
|
-
};
|
|
977
|
-
|
|
978
|
-
type PadroneAPICommand<TCommand extends AnyPadroneCommand> = (args: GetArguments<'in', TCommand>) => GetResults<TCommand>;
|
|
979
|
-
|
|
980
|
-
type NormalizeArguments<TArgs> = IsGeneric<TArgs> extends true ? void | EmptyRecord : TArgs;
|
|
981
|
-
type GetArguments<TDir extends 'in' | 'out', TCommand extends AnyPadroneCommand> = TDir extends 'in'
|
|
982
|
-
? NormalizeArguments<TCommand['~types']['argsInput']>
|
|
983
|
-
: NormalizeArguments<TCommand['~types']['argsOutput']>;
|
|
984
|
-
|
|
985
|
-
type GetResults<TCommand extends AnyPadroneCommand> = ReturnType<NonNullable<TCommand['action']>>;
|
|
986
|
-
|
|
987
|
-
type GetArgsMeta<TArgs extends PadroneSchema> = PadroneArgsSchemaMeta<NonNullable<StandardSchemaV1.InferInput<TArgs>>>;
|
|
988
|
-
|
|
989
|
-
// ---------------------------------------------------------------------------
|
|
990
|
-
// Plugin system
|
|
991
|
-
// ---------------------------------------------------------------------------
|
|
992
|
-
|
|
993
|
-
/** Base context shared across all plugin phases within a single execution. */
|
|
994
|
-
export type PluginBaseContext = {
|
|
995
|
-
/** The resolved command for this execution. In the parse phase, this is the root program. */
|
|
996
|
-
command: AnyPadroneCommand;
|
|
997
|
-
/** Mutable state bag shared across phases for this execution. Plugins can store cross-phase data here. */
|
|
998
|
-
state: Record<string, unknown>;
|
|
999
|
-
};
|
|
1000
|
-
|
|
1001
|
-
/** Context for the parse phase. */
|
|
1002
|
-
export type PluginParseContext = PluginBaseContext & {
|
|
1003
|
-
/** The raw CLI input string (undefined when invoked without input). */
|
|
1004
|
-
input: string | undefined;
|
|
1005
|
-
};
|
|
1006
|
-
|
|
1007
|
-
/** Result returned by the parse phase's `next()`. */
|
|
1008
|
-
export type PluginParseResult = {
|
|
1009
|
-
command: AnyPadroneCommand;
|
|
1010
|
-
rawArgs: Record<string, unknown>;
|
|
1011
|
-
positionalArgs: string[];
|
|
1012
|
-
};
|
|
1013
|
-
|
|
1014
|
-
/** Context for the validate phase. */
|
|
1015
|
-
export type PluginValidateContext = PluginBaseContext & {
|
|
1016
|
-
/** Raw named arguments extracted by the parser. Mutable — modify before `next()` to inject/override values. */
|
|
1017
|
-
rawArgs: Record<string, unknown>;
|
|
1018
|
-
/** Positional argument strings extracted by the parser. */
|
|
1019
|
-
positionalArgs: string[];
|
|
1020
|
-
};
|
|
1021
|
-
|
|
1022
|
-
/** Result returned by the validate phase's `next()`. */
|
|
1023
|
-
export type PluginValidateResult = {
|
|
1024
|
-
args: unknown;
|
|
1025
|
-
argsResult: StandardSchemaV1.Result<unknown>;
|
|
1026
|
-
};
|
|
1027
|
-
|
|
1028
|
-
/** Context for the execute phase. */
|
|
1029
|
-
export type PluginExecuteContext = PluginBaseContext & {
|
|
1030
|
-
/** Validated arguments that will be passed to the action. Mutable — modify before `next()` to override. */
|
|
1031
|
-
args: unknown;
|
|
1032
|
-
};
|
|
1033
|
-
|
|
1034
|
-
/** Result returned by the execute phase's `next()`. */
|
|
1035
|
-
export type PluginExecuteResult = {
|
|
1036
|
-
result: unknown;
|
|
1037
|
-
};
|
|
1038
|
-
|
|
1039
|
-
/** Context for the start phase. Runs before parsing, wraps the entire pipeline. */
|
|
1040
|
-
export type PluginStartContext = PluginBaseContext & {
|
|
1041
|
-
/** The raw CLI input string (undefined when invoked without input). */
|
|
1042
|
-
input: string | undefined;
|
|
1043
|
-
};
|
|
1044
|
-
|
|
1045
|
-
/** Context for the error phase. Called when the pipeline throws. */
|
|
1046
|
-
export type PluginErrorContext = PluginBaseContext & {
|
|
1047
|
-
/** The error that was thrown. */
|
|
1048
|
-
error: unknown;
|
|
1049
|
-
};
|
|
1050
|
-
|
|
1051
|
-
/** Result returned by the error phase's `next()`. */
|
|
1052
|
-
export type PluginErrorResult = {
|
|
1053
|
-
/** The error (possibly transformed). Set to `undefined` to suppress the error. */
|
|
1054
|
-
error?: unknown;
|
|
1055
|
-
/** A replacement result when suppressing the error. */
|
|
1056
|
-
result?: unknown;
|
|
1057
|
-
};
|
|
1058
|
-
|
|
1059
|
-
/** Context for the shutdown phase. Always runs after the pipeline (success or failure). */
|
|
1060
|
-
export type PluginShutdownContext = PluginBaseContext & {
|
|
1061
|
-
/** The error, if the pipeline failed (after error phase processing). */
|
|
1062
|
-
error?: unknown;
|
|
1063
|
-
/** The pipeline result, if it succeeded. */
|
|
1064
|
-
result?: unknown;
|
|
1065
|
-
};
|
|
1066
|
-
|
|
1067
|
-
type PluginPhaseHandler<TCtx, TResult> = (ctx: TCtx, next: () => TResult | Promise<TResult>) => TResult | Promise<TResult>;
|
|
1068
|
-
|
|
1069
|
-
/**
|
|
1070
|
-
* A Padrone plugin that can intercept the parse, validate, and execute phases of command execution.
|
|
1071
|
-
* Plugins are registered at the program level with `.use()` and apply to all commands.
|
|
1072
|
-
*
|
|
1073
|
-
* Each phase handler receives a context and a `next()` function (onion/middleware pattern):
|
|
1074
|
-
* - Call `next()` to proceed to the next plugin or the core operation.
|
|
1075
|
-
* - Return without calling `next()` to short-circuit.
|
|
1076
|
-
* - Wrap `next()` in try/catch for error handling.
|
|
1077
|
-
* - Modify context fields before `next()` to alter inputs.
|
|
1078
|
-
* - Transform the return value of `next()` to alter outputs.
|
|
1079
|
-
*/
|
|
1080
|
-
export type PadronePlugin = {
|
|
1081
|
-
/** Unique name for this plugin. Used for identification and future disable/override support. */
|
|
1082
|
-
name: string;
|
|
1083
|
-
/**
|
|
1084
|
-
* Ordering hint. Lower values run as outer layers (earlier before `next()`, later after).
|
|
1085
|
-
* Plugins with the same order preserve registration order. Defaults to `0`.
|
|
1086
|
-
*/
|
|
1087
|
-
order?: number;
|
|
1088
|
-
/**
|
|
1089
|
-
* Runs before the pipeline (parse → validate → execute). `next()` proceeds to the pipeline.
|
|
1090
|
-
* Root plugins only. Use for startup tasks like telemetry, update checks, or global config loading.
|
|
1091
|
-
*/
|
|
1092
|
-
start?: PluginPhaseHandler<PluginStartContext, unknown>;
|
|
1093
|
-
/** Intercepts command routing and raw argument extraction. */
|
|
1094
|
-
parse?: PluginPhaseHandler<PluginParseContext, PluginParseResult>;
|
|
1095
|
-
/** Intercepts argument preprocessing, interactive prompting, and schema validation. */
|
|
1096
|
-
validate?: PluginPhaseHandler<PluginValidateContext, PluginValidateResult>;
|
|
1097
|
-
/** Intercepts handler execution. */
|
|
1098
|
-
execute?: PluginPhaseHandler<PluginExecuteContext, PluginExecuteResult>;
|
|
1099
|
-
/**
|
|
1100
|
-
* Called when the pipeline throws an error. `next()` passes to the next error handler
|
|
1101
|
-
* (innermost returns `{ error }` unchanged). Return `{ result }` without `error` to suppress.
|
|
1102
|
-
*/
|
|
1103
|
-
error?: PluginPhaseHandler<PluginErrorContext, PluginErrorResult>;
|
|
1104
|
-
/**
|
|
1105
|
-
* Always runs after the pipeline completes (success or failure). `next()` calls the next shutdown handler.
|
|
1106
|
-
* Use for cleanup: closing connections, flushing logs, etc.
|
|
1107
|
-
*/
|
|
1108
|
-
shutdown?: PluginPhaseHandler<PluginShutdownContext, void>;
|
|
1109
|
-
};
|