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
|
@@ -0,0 +1,697 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import type { Tool } from 'ai';
|
|
3
|
+
import type { PadroneRuntime } from '../core/runtime.ts';
|
|
4
|
+
import type { PadroneMcpPreferences } from '../feature/mcp.ts';
|
|
5
|
+
import type { PadroneServePreferences } from '../feature/serve.ts';
|
|
6
|
+
import type { WrapConfig, WrapResult } from '../feature/wrap.ts';
|
|
7
|
+
import type { HelpPreferences } from '../output/help.ts';
|
|
8
|
+
import type {
|
|
9
|
+
FindDirectChild,
|
|
10
|
+
FlattenCommands,
|
|
11
|
+
FullCommandName,
|
|
12
|
+
MaybePromise,
|
|
13
|
+
OrAsync,
|
|
14
|
+
OrAsyncMeta,
|
|
15
|
+
PickCommandByName,
|
|
16
|
+
PickCommandByPossibleCommands,
|
|
17
|
+
PossibleCommands,
|
|
18
|
+
RepathCommands,
|
|
19
|
+
ReplaceOrAppendCommand,
|
|
20
|
+
SafeString,
|
|
21
|
+
} from '../util/type-utils.ts';
|
|
22
|
+
import type {
|
|
23
|
+
AnyPadroneCommand,
|
|
24
|
+
CommandTypesBase,
|
|
25
|
+
GetArgsMeta,
|
|
26
|
+
PadroneActionContext,
|
|
27
|
+
PadroneCommand,
|
|
28
|
+
PadroneCommandConfig,
|
|
29
|
+
PadroneProgramMeta,
|
|
30
|
+
} from './command.ts';
|
|
31
|
+
import type {
|
|
32
|
+
ExtractInterceptorContext,
|
|
33
|
+
InterceptorFactory,
|
|
34
|
+
InterceptorMeta,
|
|
35
|
+
InterceptorRequiresCheck,
|
|
36
|
+
InterceptorRequiresError,
|
|
37
|
+
PadroneContextInterceptor,
|
|
38
|
+
PadroneInterceptorFn,
|
|
39
|
+
} from './interceptor.ts';
|
|
40
|
+
import type { PadroneCliPreferences, PadroneEvalPreferences, PadroneReplPreferences } from './preferences.ts';
|
|
41
|
+
import type {
|
|
42
|
+
GetArguments,
|
|
43
|
+
MaybePromiseCommandResult,
|
|
44
|
+
PadroneAPI,
|
|
45
|
+
PadroneCommandResult,
|
|
46
|
+
PadroneDrainResult,
|
|
47
|
+
PadroneParseResult,
|
|
48
|
+
} from './result.ts';
|
|
49
|
+
import type { PadroneSchema } from './schema.ts';
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Helper type to set aliases on a command type.
|
|
53
|
+
* Uses intersection to override just the aliases while preserving all other type information.
|
|
54
|
+
*/
|
|
55
|
+
type WithAliases<TCommand extends AnyPadroneCommand, TAliases extends string[]> = Omit<TCommand, 'aliases' | '~types'> & {
|
|
56
|
+
aliases?: TAliases;
|
|
57
|
+
'~types': Omit<TCommand['~types'], 'aliases'> & { aliases: TAliases };
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Resolves aliases for a command override: if new aliases are provided (non-empty), use them;
|
|
62
|
+
* otherwise, preserve the existing command's aliases.
|
|
63
|
+
*/
|
|
64
|
+
type ResolvedAliases<
|
|
65
|
+
TCommands extends [...AnyPadroneCommand[]],
|
|
66
|
+
TNameNested extends string,
|
|
67
|
+
TAliases extends string[],
|
|
68
|
+
> = TAliases extends []
|
|
69
|
+
? FindDirectChild<TCommands, TNameNested> extends infer E extends AnyPadroneCommand
|
|
70
|
+
? E['~types']['aliases']
|
|
71
|
+
: []
|
|
72
|
+
: TAliases;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* When TContext is `unknown` (no `.context()` called), context param is optional.
|
|
76
|
+
* Otherwise it is required.
|
|
77
|
+
*/
|
|
78
|
+
type ContextParam<TContext> = unknown extends TContext ? { context?: TContext } : { context: TContext };
|
|
79
|
+
|
|
80
|
+
/** Options for the `mount()` method. */
|
|
81
|
+
type MountOptions<TContext, TNewContext> = { context: (ctx: TContext) => TNewContext };
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Resolves the initial builder type for a `.command()` call.
|
|
85
|
+
* If TNameNested already exists in TCommands, the builder starts pre-populated with that command's types.
|
|
86
|
+
* Otherwise, a fresh builder with default types is used.
|
|
87
|
+
*/
|
|
88
|
+
type InitialCommandBuilder<
|
|
89
|
+
TProgramName extends string,
|
|
90
|
+
TNameNested extends string,
|
|
91
|
+
TParentPath extends string,
|
|
92
|
+
TParentArgs extends PadroneSchema,
|
|
93
|
+
TCommands extends [...AnyPadroneCommand[]],
|
|
94
|
+
TParentContext,
|
|
95
|
+
> = [FindDirectChild<TCommands, TNameNested>] extends [never]
|
|
96
|
+
? PadroneBuilder<TProgramName, TNameNested, TParentPath, PadroneSchema<void>, void, [], TParentArgs, false, TParentContext>
|
|
97
|
+
: FindDirectChild<TCommands, TNameNested> extends infer E extends AnyPadroneCommand
|
|
98
|
+
? PadroneBuilder<
|
|
99
|
+
TProgramName,
|
|
100
|
+
TNameNested,
|
|
101
|
+
TParentPath,
|
|
102
|
+
E['~types']['argsSchema'],
|
|
103
|
+
E['~types']['result'],
|
|
104
|
+
E['~types']['commands'],
|
|
105
|
+
TParentArgs,
|
|
106
|
+
E['~types']['async'],
|
|
107
|
+
E['~types']['context'],
|
|
108
|
+
E['~types']['contextProvided']
|
|
109
|
+
>
|
|
110
|
+
: PadroneBuilder<TProgramName, TNameNested, TParentPath, PadroneSchema<void>, void, [], TParentArgs, false, TParentContext>;
|
|
111
|
+
|
|
112
|
+
export type AnyPadroneBuilder = InitialCommandBuilder<string, string, string, any, [...AnyPadroneCommand[]], any>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Like InitialCommandBuilder but uses `any` for args in the fresh case.
|
|
116
|
+
* Used as the default for TBuilder when no builderFn is provided.
|
|
117
|
+
*/
|
|
118
|
+
type DefaultCommandBuilder<
|
|
119
|
+
TProgramName extends string,
|
|
120
|
+
TNameNested extends string,
|
|
121
|
+
TParentPath extends string,
|
|
122
|
+
TParentArgs extends PadroneSchema,
|
|
123
|
+
TCommands extends [...AnyPadroneCommand[]],
|
|
124
|
+
TParentContext,
|
|
125
|
+
> = [FindDirectChild<TCommands, TNameNested>] extends [never]
|
|
126
|
+
? PadroneBuilder<TProgramName, TNameNested, TParentPath, any, void, [], TParentArgs, false, TParentContext>
|
|
127
|
+
: FindDirectChild<TCommands, TNameNested> extends infer E extends AnyPadroneCommand
|
|
128
|
+
? PadroneBuilder<
|
|
129
|
+
TProgramName,
|
|
130
|
+
TNameNested,
|
|
131
|
+
TParentPath,
|
|
132
|
+
E['~types']['argsSchema'],
|
|
133
|
+
E['~types']['result'],
|
|
134
|
+
E['~types']['commands'],
|
|
135
|
+
TParentArgs,
|
|
136
|
+
E['~types']['async'],
|
|
137
|
+
E['~types']['context'],
|
|
138
|
+
E['~types']['contextProvided']
|
|
139
|
+
>
|
|
140
|
+
: PadroneBuilder<TProgramName, TNameNested, TParentPath, any, void, [], TParentArgs, false, TParentContext>;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Conditional type that returns either PadroneBuilder or PadroneProgram based on TReturn.
|
|
144
|
+
* Used to avoid repetition in PadroneBuilderMethods return types.
|
|
145
|
+
*/
|
|
146
|
+
type BuilderOrProgram<
|
|
147
|
+
TReturn extends 'builder' | 'program',
|
|
148
|
+
TProgramName extends string,
|
|
149
|
+
TName extends string,
|
|
150
|
+
TParentName extends string,
|
|
151
|
+
TArgs extends PadroneSchema,
|
|
152
|
+
TRes,
|
|
153
|
+
TCommands extends [...AnyPadroneCommand[]],
|
|
154
|
+
TParentArgs extends PadroneSchema,
|
|
155
|
+
TAsync extends boolean,
|
|
156
|
+
TContext,
|
|
157
|
+
TContextProvided = unknown,
|
|
158
|
+
> = TReturn extends 'builder'
|
|
159
|
+
? PadroneBuilder<TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided>
|
|
160
|
+
: PadroneProgram<TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided>;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Base builder methods shared between PadroneBuilder and PadroneProgram.
|
|
164
|
+
* These methods are used for defining command structure (arguments, action, subcommands).
|
|
165
|
+
*/
|
|
166
|
+
export type PadroneBuilderMethods<
|
|
167
|
+
TProgramName extends string,
|
|
168
|
+
TName extends string,
|
|
169
|
+
TParentName extends string,
|
|
170
|
+
TArgs extends PadroneSchema,
|
|
171
|
+
TRes,
|
|
172
|
+
TCommands extends [...AnyPadroneCommand[]],
|
|
173
|
+
TParentArgs extends PadroneSchema,
|
|
174
|
+
TAsync extends boolean,
|
|
175
|
+
TContext,
|
|
176
|
+
TContextProvided,
|
|
177
|
+
/** The return type for builder methods - either PadroneBuilder or PadroneProgram */
|
|
178
|
+
TReturn extends 'builder' | 'program',
|
|
179
|
+
> = {
|
|
180
|
+
/** Apply a build-time extension that transforms this builder/program. @category Builder */
|
|
181
|
+
extend: <TResult extends CommandTypesBase>(
|
|
182
|
+
extension: PadroneExtension<
|
|
183
|
+
BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided>,
|
|
184
|
+
TResult
|
|
185
|
+
>,
|
|
186
|
+
) => TResult;
|
|
187
|
+
|
|
188
|
+
/** Register a runtime interceptor for lifecycle phases (parse, validate, execute, etc.). @category Builder */
|
|
189
|
+
intercept: {
|
|
190
|
+
/** Context-providing interceptor — extends context type. Rejects if required context is not satisfied. */
|
|
191
|
+
<TInterceptor extends PadroneContextInterceptor<any, StandardSchemaV1.InferOutput<TArgs>, TRes, any>>(
|
|
192
|
+
interceptor: TInterceptor,
|
|
193
|
+
): InterceptorRequiresCheck<TInterceptor, TContext & TContextProvided> extends true
|
|
194
|
+
? BuilderOrProgram<
|
|
195
|
+
TReturn,
|
|
196
|
+
TProgramName,
|
|
197
|
+
TName,
|
|
198
|
+
TParentName,
|
|
199
|
+
TArgs,
|
|
200
|
+
TRes,
|
|
201
|
+
TCommands,
|
|
202
|
+
TParentArgs,
|
|
203
|
+
TAsync,
|
|
204
|
+
TContext,
|
|
205
|
+
TContextProvided & ExtractInterceptorContext<TInterceptor>
|
|
206
|
+
>
|
|
207
|
+
: InterceptorRequiresError;
|
|
208
|
+
/** Plain interceptor — no context change. Rejects if required context is not satisfied. */
|
|
209
|
+
<TInterceptor extends PadroneInterceptorFn<StandardSchemaV1.InferOutput<TArgs>, TRes, any>>(
|
|
210
|
+
interceptor: TInterceptor,
|
|
211
|
+
): InterceptorRequiresCheck<TInterceptor, TContext & TContextProvided> extends true
|
|
212
|
+
? BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided>
|
|
213
|
+
: InterceptorRequiresError;
|
|
214
|
+
/** Register an interceptor with static metadata and a factory function. Context is strongly typed. */
|
|
215
|
+
(
|
|
216
|
+
meta: InterceptorMeta,
|
|
217
|
+
factory: InterceptorFactory<StandardSchemaV1.InferOutput<TArgs>, TRes, TContext & TContextProvided>,
|
|
218
|
+
): BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided>;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/** Set command metadata like title, description, version, hidden, deprecated, etc. @category Builder */
|
|
222
|
+
configure: (
|
|
223
|
+
config: PadroneCommandConfig,
|
|
224
|
+
) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided>;
|
|
225
|
+
|
|
226
|
+
/** Override the runtime adapter (process, IO, environment). @category Builder */
|
|
227
|
+
runtime: (
|
|
228
|
+
runtime: PadroneRuntime,
|
|
229
|
+
) => BuilderOrProgram<TReturn, TProgramName, TName, TParentName, TArgs, TRes, TCommands, TParentArgs, TAsync, TContext, TContextProvided>;
|
|
230
|
+
|
|
231
|
+
/** Mark this command as async, forcing all return types to be `Promise`-wrapped. @category Builder */
|
|
232
|
+
async: () => BuilderOrProgram<
|
|
233
|
+
TReturn,
|
|
234
|
+
TProgramName,
|
|
235
|
+
TName,
|
|
236
|
+
TParentName,
|
|
237
|
+
TArgs,
|
|
238
|
+
TRes,
|
|
239
|
+
TCommands,
|
|
240
|
+
TParentArgs,
|
|
241
|
+
true,
|
|
242
|
+
TContext,
|
|
243
|
+
TContextProvided
|
|
244
|
+
>;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Declare or transform the user-defined context type for this command.
|
|
248
|
+
*
|
|
249
|
+
* - Without a callback: narrows the context type (type-only, no runtime transform).
|
|
250
|
+
* - With a callback: transforms the parent/current context into a new type. Chainable — multiple calls compose.
|
|
251
|
+
*
|
|
252
|
+
* Interceptor-provided context (`TContextProvided`) is preserved across `.context()` calls.
|
|
253
|
+
* @category Builder
|
|
254
|
+
*/
|
|
255
|
+
context: {
|
|
256
|
+
<TNewContext>(): BuilderOrProgram<
|
|
257
|
+
TReturn,
|
|
258
|
+
TProgramName,
|
|
259
|
+
TName,
|
|
260
|
+
TParentName,
|
|
261
|
+
TArgs,
|
|
262
|
+
TRes,
|
|
263
|
+
TCommands,
|
|
264
|
+
TParentArgs,
|
|
265
|
+
TAsync,
|
|
266
|
+
TNewContext,
|
|
267
|
+
TContextProvided
|
|
268
|
+
>;
|
|
269
|
+
<TNewContext>(
|
|
270
|
+
transform: (ctx: TContext) => TNewContext,
|
|
271
|
+
): BuilderOrProgram<
|
|
272
|
+
TReturn,
|
|
273
|
+
TProgramName,
|
|
274
|
+
TName,
|
|
275
|
+
TParentName,
|
|
276
|
+
TArgs,
|
|
277
|
+
TRes,
|
|
278
|
+
TCommands,
|
|
279
|
+
TParentArgs,
|
|
280
|
+
TAsync,
|
|
281
|
+
TNewContext,
|
|
282
|
+
TContextProvided
|
|
283
|
+
>;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/** Define the argument/option schema for this command. Accepts a Standard Schema or a function that extends the parent schema. @category Builder */
|
|
287
|
+
arguments: <TNewArgs extends PadroneSchema = PadroneSchema<void>, TMeta extends GetArgsMeta<TNewArgs> = GetArgsMeta<TNewArgs>>(
|
|
288
|
+
schema?: TNewArgs | ((parentSchema: TParentArgs) => TNewArgs),
|
|
289
|
+
meta?: TMeta,
|
|
290
|
+
) => BuilderOrProgram<
|
|
291
|
+
TReturn,
|
|
292
|
+
TProgramName,
|
|
293
|
+
TName,
|
|
294
|
+
TParentName,
|
|
295
|
+
TNewArgs,
|
|
296
|
+
TRes,
|
|
297
|
+
TCommands,
|
|
298
|
+
TParentArgs,
|
|
299
|
+
OrAsyncMeta<OrAsync<TAsync, TNewArgs>, TMeta>,
|
|
300
|
+
TContext,
|
|
301
|
+
TContextProvided
|
|
302
|
+
>;
|
|
303
|
+
|
|
304
|
+
/** Set the handler function that runs when this command is executed. @category Builder */
|
|
305
|
+
action: <TNewRes>(
|
|
306
|
+
handler?: (
|
|
307
|
+
args: StandardSchemaV1.InferOutput<TArgs>,
|
|
308
|
+
ctx: PadroneActionContext<TContext & TContextProvided>,
|
|
309
|
+
base: (args: StandardSchemaV1.InferOutput<TArgs>, ctx: PadroneActionContext<TContext & TContextProvided>) => TRes,
|
|
310
|
+
) => TNewRes,
|
|
311
|
+
) => BuilderOrProgram<
|
|
312
|
+
TReturn,
|
|
313
|
+
TProgramName,
|
|
314
|
+
TName,
|
|
315
|
+
TParentName,
|
|
316
|
+
TArgs,
|
|
317
|
+
TNewRes,
|
|
318
|
+
TCommands,
|
|
319
|
+
TParentArgs,
|
|
320
|
+
TAsync,
|
|
321
|
+
TContext,
|
|
322
|
+
TContextProvided
|
|
323
|
+
>;
|
|
324
|
+
|
|
325
|
+
/** Wrap an external CLI tool, delegating execution to a shell command. @category Builder */
|
|
326
|
+
wrap: <TWrapArgs extends PadroneSchema = TArgs>(
|
|
327
|
+
config: WrapConfig<TArgs, TWrapArgs>,
|
|
328
|
+
) => BuilderOrProgram<
|
|
329
|
+
TReturn,
|
|
330
|
+
TProgramName,
|
|
331
|
+
TName,
|
|
332
|
+
TParentName,
|
|
333
|
+
TArgs,
|
|
334
|
+
Promise<WrapResult>,
|
|
335
|
+
TCommands,
|
|
336
|
+
TParentArgs,
|
|
337
|
+
TAsync,
|
|
338
|
+
TContext,
|
|
339
|
+
TContextProvided
|
|
340
|
+
>;
|
|
341
|
+
|
|
342
|
+
/** Add or override a subcommand. Pass a builder function to define its schema, action, and nested commands. @category Builder */
|
|
343
|
+
command: <
|
|
344
|
+
TNameNested extends string,
|
|
345
|
+
TAliases extends string[] = [],
|
|
346
|
+
TBuilder extends CommandTypesBase = DefaultCommandBuilder<
|
|
347
|
+
TProgramName,
|
|
348
|
+
TNameNested,
|
|
349
|
+
FullCommandName<TName, TParentName>,
|
|
350
|
+
TArgs,
|
|
351
|
+
TCommands,
|
|
352
|
+
TContext & TContextProvided
|
|
353
|
+
>,
|
|
354
|
+
>(
|
|
355
|
+
name: TNameNested | readonly [TNameNested, ...TAliases],
|
|
356
|
+
builderFn?: (
|
|
357
|
+
builder: InitialCommandBuilder<
|
|
358
|
+
TProgramName,
|
|
359
|
+
TNameNested,
|
|
360
|
+
FullCommandName<TName, TParentName>,
|
|
361
|
+
TArgs,
|
|
362
|
+
TCommands,
|
|
363
|
+
TContext & TContextProvided
|
|
364
|
+
>,
|
|
365
|
+
) => TBuilder,
|
|
366
|
+
) => BuilderOrProgram<
|
|
367
|
+
TReturn,
|
|
368
|
+
TProgramName,
|
|
369
|
+
TName,
|
|
370
|
+
TParentName,
|
|
371
|
+
TArgs,
|
|
372
|
+
TRes,
|
|
373
|
+
TCommands extends []
|
|
374
|
+
? [WithAliases<TBuilder['~types']['command'], TAliases>]
|
|
375
|
+
: AnyPadroneCommand[] extends TCommands
|
|
376
|
+
? [WithAliases<TBuilder['~types']['command'], TAliases>]
|
|
377
|
+
: ReplaceOrAppendCommand<
|
|
378
|
+
TCommands,
|
|
379
|
+
TNameNested,
|
|
380
|
+
WithAliases<TBuilder['~types']['command'], ResolvedAliases<TCommands, TNameNested, TAliases>>
|
|
381
|
+
>,
|
|
382
|
+
TParentArgs,
|
|
383
|
+
TAsync,
|
|
384
|
+
TContext,
|
|
385
|
+
TContextProvided
|
|
386
|
+
>;
|
|
387
|
+
|
|
388
|
+
/** Mount an existing program as a subcommand, optionally transforming the context. @category Builder */
|
|
389
|
+
mount: {
|
|
390
|
+
<TNameNested extends string, TAliases extends string[] = [], TProgram extends CommandTypesBase = CommandTypesBase>(
|
|
391
|
+
name: TNameNested | readonly [TNameNested, ...TAliases],
|
|
392
|
+
program: TProgram,
|
|
393
|
+
): BuilderOrProgram<
|
|
394
|
+
TReturn,
|
|
395
|
+
TProgramName,
|
|
396
|
+
TName,
|
|
397
|
+
TParentName,
|
|
398
|
+
TArgs,
|
|
399
|
+
TRes,
|
|
400
|
+
TCommands extends []
|
|
401
|
+
? [
|
|
402
|
+
WithAliases<
|
|
403
|
+
PadroneCommand<
|
|
404
|
+
TNameNested,
|
|
405
|
+
FullCommandName<TName, TParentName>,
|
|
406
|
+
TProgram['~types']['command']['~types']['argsSchema'],
|
|
407
|
+
TProgram['~types']['command']['~types']['result'],
|
|
408
|
+
RepathCommands<
|
|
409
|
+
TProgram['~types']['command']['~types']['commands'],
|
|
410
|
+
FullCommandName<TNameNested, FullCommandName<TName, TParentName>>
|
|
411
|
+
>,
|
|
412
|
+
[],
|
|
413
|
+
TProgram['~types']['command']['~types']['async'],
|
|
414
|
+
TContext & TContextProvided
|
|
415
|
+
>,
|
|
416
|
+
TAliases
|
|
417
|
+
>,
|
|
418
|
+
]
|
|
419
|
+
: AnyPadroneCommand[] extends TCommands
|
|
420
|
+
? [
|
|
421
|
+
WithAliases<
|
|
422
|
+
PadroneCommand<
|
|
423
|
+
TNameNested,
|
|
424
|
+
FullCommandName<TName, TParentName>,
|
|
425
|
+
TProgram['~types']['command']['~types']['argsSchema'],
|
|
426
|
+
TProgram['~types']['command']['~types']['result'],
|
|
427
|
+
RepathCommands<
|
|
428
|
+
TProgram['~types']['command']['~types']['commands'],
|
|
429
|
+
FullCommandName<TNameNested, FullCommandName<TName, TParentName>>
|
|
430
|
+
>,
|
|
431
|
+
[],
|
|
432
|
+
TProgram['~types']['command']['~types']['async'],
|
|
433
|
+
TContext & TContextProvided
|
|
434
|
+
>,
|
|
435
|
+
TAliases
|
|
436
|
+
>,
|
|
437
|
+
]
|
|
438
|
+
: ReplaceOrAppendCommand<
|
|
439
|
+
TCommands,
|
|
440
|
+
TNameNested,
|
|
441
|
+
WithAliases<
|
|
442
|
+
PadroneCommand<
|
|
443
|
+
TNameNested,
|
|
444
|
+
FullCommandName<TName, TParentName>,
|
|
445
|
+
TProgram['~types']['command']['~types']['argsSchema'],
|
|
446
|
+
TProgram['~types']['command']['~types']['result'],
|
|
447
|
+
RepathCommands<
|
|
448
|
+
TProgram['~types']['command']['~types']['commands'],
|
|
449
|
+
FullCommandName<TNameNested, FullCommandName<TName, TParentName>>
|
|
450
|
+
>,
|
|
451
|
+
[],
|
|
452
|
+
TProgram['~types']['command']['~types']['async'],
|
|
453
|
+
TContext & TContextProvided
|
|
454
|
+
>,
|
|
455
|
+
ResolvedAliases<TCommands, TNameNested, TAliases>
|
|
456
|
+
>
|
|
457
|
+
>,
|
|
458
|
+
TParentArgs,
|
|
459
|
+
TAsync,
|
|
460
|
+
TContext,
|
|
461
|
+
TContextProvided
|
|
462
|
+
>;
|
|
463
|
+
|
|
464
|
+
<
|
|
465
|
+
TNameNested extends string,
|
|
466
|
+
TAliases extends string[] = [],
|
|
467
|
+
TProgram extends CommandTypesBase = CommandTypesBase,
|
|
468
|
+
TNewContext = unknown,
|
|
469
|
+
>(
|
|
470
|
+
name: TNameNested | readonly [TNameNested, ...TAliases],
|
|
471
|
+
program: TProgram,
|
|
472
|
+
options: MountOptions<TContext & TContextProvided, TNewContext>,
|
|
473
|
+
): BuilderOrProgram<
|
|
474
|
+
TReturn,
|
|
475
|
+
TProgramName,
|
|
476
|
+
TName,
|
|
477
|
+
TParentName,
|
|
478
|
+
TArgs,
|
|
479
|
+
TRes,
|
|
480
|
+
TCommands extends []
|
|
481
|
+
? [
|
|
482
|
+
WithAliases<
|
|
483
|
+
PadroneCommand<
|
|
484
|
+
TNameNested,
|
|
485
|
+
FullCommandName<TName, TParentName>,
|
|
486
|
+
TProgram['~types']['command']['~types']['argsSchema'],
|
|
487
|
+
TProgram['~types']['command']['~types']['result'],
|
|
488
|
+
RepathCommands<
|
|
489
|
+
TProgram['~types']['command']['~types']['commands'],
|
|
490
|
+
FullCommandName<TNameNested, FullCommandName<TName, TParentName>>
|
|
491
|
+
>,
|
|
492
|
+
[],
|
|
493
|
+
TProgram['~types']['command']['~types']['async'],
|
|
494
|
+
TNewContext
|
|
495
|
+
>,
|
|
496
|
+
TAliases
|
|
497
|
+
>,
|
|
498
|
+
]
|
|
499
|
+
: AnyPadroneCommand[] extends TCommands
|
|
500
|
+
? [
|
|
501
|
+
WithAliases<
|
|
502
|
+
PadroneCommand<
|
|
503
|
+
TNameNested,
|
|
504
|
+
FullCommandName<TName, TParentName>,
|
|
505
|
+
TProgram['~types']['command']['~types']['argsSchema'],
|
|
506
|
+
TProgram['~types']['command']['~types']['result'],
|
|
507
|
+
RepathCommands<
|
|
508
|
+
TProgram['~types']['command']['~types']['commands'],
|
|
509
|
+
FullCommandName<TNameNested, FullCommandName<TName, TParentName>>
|
|
510
|
+
>,
|
|
511
|
+
[],
|
|
512
|
+
TProgram['~types']['command']['~types']['async'],
|
|
513
|
+
TNewContext
|
|
514
|
+
>,
|
|
515
|
+
TAliases
|
|
516
|
+
>,
|
|
517
|
+
]
|
|
518
|
+
: ReplaceOrAppendCommand<
|
|
519
|
+
TCommands,
|
|
520
|
+
TNameNested,
|
|
521
|
+
WithAliases<
|
|
522
|
+
PadroneCommand<
|
|
523
|
+
TNameNested,
|
|
524
|
+
FullCommandName<TName, TParentName>,
|
|
525
|
+
TProgram['~types']['command']['~types']['argsSchema'],
|
|
526
|
+
TProgram['~types']['command']['~types']['result'],
|
|
527
|
+
RepathCommands<
|
|
528
|
+
TProgram['~types']['command']['~types']['commands'],
|
|
529
|
+
FullCommandName<TNameNested, FullCommandName<TName, TParentName>>
|
|
530
|
+
>,
|
|
531
|
+
[],
|
|
532
|
+
TProgram['~types']['command']['~types']['async'],
|
|
533
|
+
TNewContext
|
|
534
|
+
>,
|
|
535
|
+
ResolvedAliases<TCommands, TNameNested, TAliases>
|
|
536
|
+
>
|
|
537
|
+
>,
|
|
538
|
+
TParentArgs,
|
|
539
|
+
TAsync,
|
|
540
|
+
TContext,
|
|
541
|
+
TContextProvided
|
|
542
|
+
>;
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
/** @deprecated Internal use only */
|
|
546
|
+
'~types': {
|
|
547
|
+
programName: TProgramName;
|
|
548
|
+
name: TName;
|
|
549
|
+
parentName: TParentName;
|
|
550
|
+
path: FullCommandName<TName, TParentName>;
|
|
551
|
+
aliases: [];
|
|
552
|
+
argsSchema: TArgs;
|
|
553
|
+
result: TRes;
|
|
554
|
+
commands: TCommands;
|
|
555
|
+
async: TAsync;
|
|
556
|
+
context: TContext;
|
|
557
|
+
contextProvided: TContextProvided;
|
|
558
|
+
command: PadroneCommand<TName, TParentName, TArgs, TRes, TCommands, [], TAsync, TContext, TContextProvided>;
|
|
559
|
+
};
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
export type PadroneBuilder<
|
|
563
|
+
TProgramName extends string = '',
|
|
564
|
+
TName extends string = string,
|
|
565
|
+
TParentName extends string = '',
|
|
566
|
+
TArgs extends PadroneSchema = PadroneSchema<DefaultArgs>,
|
|
567
|
+
TRes = void,
|
|
568
|
+
TCommands extends [...AnyPadroneCommand[]] = [],
|
|
569
|
+
TParentArgs extends PadroneSchema = PadroneSchema<void>,
|
|
570
|
+
TAsync extends boolean = false,
|
|
571
|
+
TContext = unknown,
|
|
572
|
+
TContextProvided = unknown,
|
|
573
|
+
> = PadroneBuilderMethods<
|
|
574
|
+
TProgramName,
|
|
575
|
+
TName,
|
|
576
|
+
TParentName,
|
|
577
|
+
TArgs,
|
|
578
|
+
TRes,
|
|
579
|
+
TCommands,
|
|
580
|
+
TParentArgs,
|
|
581
|
+
TAsync,
|
|
582
|
+
TContext,
|
|
583
|
+
TContextProvided,
|
|
584
|
+
'builder'
|
|
585
|
+
>;
|
|
586
|
+
|
|
587
|
+
export type PadroneProgram<
|
|
588
|
+
TProgramName extends string = '',
|
|
589
|
+
TName extends string = string,
|
|
590
|
+
TParentName extends string = '',
|
|
591
|
+
TArgs extends PadroneSchema = PadroneSchema<DefaultArgs>,
|
|
592
|
+
TRes = void,
|
|
593
|
+
TCommands extends [...AnyPadroneCommand[]] = [],
|
|
594
|
+
TParentArgs extends PadroneSchema = PadroneSchema<void>,
|
|
595
|
+
TAsync extends boolean = false,
|
|
596
|
+
TContext = unknown,
|
|
597
|
+
TContextProvided = unknown,
|
|
598
|
+
> = PadroneBuilderMethods<
|
|
599
|
+
TProgramName,
|
|
600
|
+
TName,
|
|
601
|
+
TParentName,
|
|
602
|
+
TArgs,
|
|
603
|
+
TRes,
|
|
604
|
+
TCommands,
|
|
605
|
+
TParentArgs,
|
|
606
|
+
TAsync,
|
|
607
|
+
TContext,
|
|
608
|
+
TContextProvided,
|
|
609
|
+
'program'
|
|
610
|
+
> & {
|
|
611
|
+
/** Execute a command by name with pre-validated args (skips parsing and validation). @category Execution */
|
|
612
|
+
run: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], true, true>>(
|
|
613
|
+
name: TCommand | SafeString,
|
|
614
|
+
args: NoInfer<GetArguments<'in', PickCommandByName<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>>,
|
|
615
|
+
prefs?: ContextParam<TContext>,
|
|
616
|
+
) => PadroneCommandResult<PickCommandByName<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>;
|
|
617
|
+
|
|
618
|
+
/** Parse and execute a string input through the full interceptor pipeline. @category Execution */
|
|
619
|
+
eval: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], true, true>>(
|
|
620
|
+
input: TCommand | SafeString,
|
|
621
|
+
prefs?: PadroneEvalPreferences & ContextParam<TContext>,
|
|
622
|
+
) => MaybePromiseCommandResult<
|
|
623
|
+
PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>,
|
|
624
|
+
PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>['~types']['async']
|
|
625
|
+
>;
|
|
626
|
+
|
|
627
|
+
/** Parse and execute from `process.argv` through the full interceptor pipeline. @category Execution */
|
|
628
|
+
cli: (
|
|
629
|
+
prefs?: PadroneCliPreferences & ContextParam<TContext>,
|
|
630
|
+
) => MaybePromiseCommandResult<FlattenCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>, TAsync>;
|
|
631
|
+
|
|
632
|
+
/** Parse and validate input without executing the action. @category Execution */
|
|
633
|
+
parse: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], true, false>>(
|
|
634
|
+
input?: TCommand | SafeString,
|
|
635
|
+
) => MaybePromise<
|
|
636
|
+
PadroneParseResult<PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>,
|
|
637
|
+
PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>['~types']['async']
|
|
638
|
+
>;
|
|
639
|
+
|
|
640
|
+
/** Serialize args back into a CLI string. @category Utility */
|
|
641
|
+
stringify: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], false, true>>(
|
|
642
|
+
command?: TCommand | SafeString,
|
|
643
|
+
args?: GetArguments<'out', PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TCommand>>,
|
|
644
|
+
) => string;
|
|
645
|
+
|
|
646
|
+
/** Look up a command definition by name. @category Utility */
|
|
647
|
+
find: <const TFind extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], false, true>>(
|
|
648
|
+
command: TFind | SafeString,
|
|
649
|
+
) => PickCommandByPossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], TFind> | undefined;
|
|
650
|
+
|
|
651
|
+
/** Get a structured API representation of all commands. @category Utility */
|
|
652
|
+
api: () => PadroneAPI<PadroneCommand<'', '', TArgs, TRes, TCommands>>;
|
|
653
|
+
|
|
654
|
+
/** Start an interactive REPL session. @category Execution */
|
|
655
|
+
repl: (options?: PadroneReplPreferences<PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>>) => AsyncIterable<
|
|
656
|
+
PadroneCommandResult<FlattenCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>>
|
|
657
|
+
> & {
|
|
658
|
+
drain: () => Promise<PadroneDrainResult<PadroneCommandResult<FlattenCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>]>>[]>>;
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
/** Export as an AI SDK tool. @category Utility */
|
|
662
|
+
tool: () => Tool<{ command: string }>;
|
|
663
|
+
|
|
664
|
+
/** Generate help text for a command. @category Utility */
|
|
665
|
+
help: <const TCommand extends PossibleCommands<[PadroneCommand<'', '', TArgs, TRes, TCommands>], false, true>>(
|
|
666
|
+
command?: TCommand,
|
|
667
|
+
prefs?: HelpPreferences,
|
|
668
|
+
) => string;
|
|
669
|
+
|
|
670
|
+
/** Generate shell completion script. @category Utility */
|
|
671
|
+
completion: (shell?: 'bash' | 'zsh' | 'fish' | 'powershell') => Promise<string>;
|
|
672
|
+
|
|
673
|
+
/** Start a Model Context Protocol server. @category Server */
|
|
674
|
+
mcp: (prefs?: PadroneMcpPreferences) => Promise<void>;
|
|
675
|
+
|
|
676
|
+
/** Start a REST HTTP server with OpenAPI docs. @category Server */
|
|
677
|
+
serve: (prefs?: PadroneServePreferences) => Promise<void>;
|
|
678
|
+
|
|
679
|
+
/** Read-only metadata about the program (name, version, description, commands, etc.). @category Utility */
|
|
680
|
+
info: PadroneProgramMeta<TProgramName>;
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
export type AnyPadroneProgram = PadroneProgram<string, string, string, any, any, [...AnyPadroneCommand[]]>;
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* A build-time extension that transforms a builder/program.
|
|
687
|
+
* Extensions can add commands, arguments, interceptors, configure settings, etc.
|
|
688
|
+
*
|
|
689
|
+
* Use with `.extend(extension)`:
|
|
690
|
+
* ```ts
|
|
691
|
+
* const withAuth = (b) => b.arguments(authSchema).command('login', ...)
|
|
692
|
+
* program.extend(withAuth)
|
|
693
|
+
* ```
|
|
694
|
+
*/
|
|
695
|
+
export type PadroneExtension<TIn extends CommandTypesBase = CommandTypesBase, TOut extends CommandTypesBase = TIn> = (builder: TIn) => TOut;
|
|
696
|
+
|
|
697
|
+
type DefaultArgs = Record<string, unknown> | void;
|