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