padrone 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +330 -0
- package/index.d.mts +384 -0
- package/index.mjs +1246 -0
- package/index.mjs.map +1 -0
- package/package.json +64 -0
- package/src/colorizer.ts +41 -0
- package/src/create.ts +559 -0
- package/src/formatter.ts +499 -0
- package/src/help.ts +227 -0
- package/src/index.ts +22 -0
- package/src/options.ts +290 -0
- package/src/parse.ts +222 -0
- package/src/type-utils.ts +99 -0
- package/src/types.ts +313 -0
- package/src/utils.ts +131 -0
- package/src/zod.d.ts +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 GΓΆkhan Kurt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="media/padrone.svg" alt="Padrone Logo" width="200" height="200" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<!-- <h1 align="center">Padrone</h1> -->
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>Create type-safe, interactive CLI apps with Zod schemas</strong>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/padrone"><img src="https://img.shields.io/npm/v/padrone.svg" alt="npm version"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/padrone"><img src="https://img.shields.io/npm/dm/padrone.svg" alt="npm downloads"></a>
|
|
14
|
+
<a href="https://github.com/KurtGokhan/padrone/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/padrone.svg" alt="license"></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## β¨ Features
|
|
20
|
+
|
|
21
|
+
- π **Type-safe** - Full TypeScript support with Zod schema validation
|
|
22
|
+
- π― **Fluent API** - Chain commands, arguments, and options with a clean builder pattern
|
|
23
|
+
- π€ **AI-Ready** - First-class support for Vercel AI SDK tool integration
|
|
24
|
+
- π **Auto Help** - Automatic help generation from your schema definitions
|
|
25
|
+
- π§© **Nested Commands** - Support for deeply nested subcommands
|
|
26
|
+
- π **Standard Schema** - Built on [Standard Schema](https://github.com/standard-schema/standard-schema) for maximum compatibility
|
|
27
|
+
- π **Zero Config** - Works out of the box with sensible defaults
|
|
28
|
+
|
|
29
|
+
## π¦ Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Using npm
|
|
33
|
+
npm install padrone zod
|
|
34
|
+
|
|
35
|
+
# Using bun
|
|
36
|
+
bun add padrone zod
|
|
37
|
+
|
|
38
|
+
# Using pnpm
|
|
39
|
+
pnpm add padrone zod
|
|
40
|
+
|
|
41
|
+
# Using yarn
|
|
42
|
+
yarn add padrone zod
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## π Quick Start
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { createPadrone } from 'padrone';
|
|
49
|
+
import * as z from 'zod/v4';
|
|
50
|
+
|
|
51
|
+
const program = createPadrone('myapp')
|
|
52
|
+
.command('greet', (c) =>
|
|
53
|
+
c
|
|
54
|
+
.options(
|
|
55
|
+
z.object({
|
|
56
|
+
names: z.array(z.string()).describe('Names to greet'),
|
|
57
|
+
prefix: z
|
|
58
|
+
.string()
|
|
59
|
+
.optional()
|
|
60
|
+
.describe('Prefix to use in greeting')
|
|
61
|
+
.meta({ alias: 'p' }),
|
|
62
|
+
}),
|
|
63
|
+
{ positional: ['...names'] },
|
|
64
|
+
)
|
|
65
|
+
.action((options) => {
|
|
66
|
+
const prefix = options?.prefix ? `${options.prefix} ` : '';
|
|
67
|
+
options.names.forEach((name) => {
|
|
68
|
+
console.log(`Hello, ${prefix}${name}!`);
|
|
69
|
+
});
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
// Run from CLI arguments
|
|
74
|
+
program.cli();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Running your CLI
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Run with arguments
|
|
81
|
+
myapp greet John Jane --prefix Mr.
|
|
82
|
+
|
|
83
|
+
# Or with alias
|
|
84
|
+
myapp greet John Jane -p Mr.
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Output:
|
|
88
|
+
```
|
|
89
|
+
Hello, Mr. John!
|
|
90
|
+
Hello, Mr. Jane!
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## π Usage Examples
|
|
94
|
+
|
|
95
|
+
### Programmatic Execution
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
// Run a command directly with typed options
|
|
99
|
+
program.run('greet', { names: ['John', 'Jane'], prefix: 'Dr.' });
|
|
100
|
+
|
|
101
|
+
// Parse CLI input without executing
|
|
102
|
+
const parsed = program.parse('greet John --prefix Mr.');
|
|
103
|
+
console.log(parsed.options); // { names: ['John'], prefix: 'Mr.' }
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### API Mode
|
|
107
|
+
|
|
108
|
+
Generate a typed API from your CLI program:
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
const api = program.api();
|
|
112
|
+
|
|
113
|
+
// Call commands as functions with full type safety
|
|
114
|
+
api.greet({ names: ['Alice', 'Bob'], prefix: 'Dr.' });
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Nested Commands
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
const program = createPadrone('weather')
|
|
121
|
+
.command('forecast', (c) =>
|
|
122
|
+
c
|
|
123
|
+
.options(
|
|
124
|
+
z.object({
|
|
125
|
+
city: z.string().describe('City name'),
|
|
126
|
+
days: z.number().optional().default(3).describe('Number of days'),
|
|
127
|
+
}),
|
|
128
|
+
{ positional: ['city'] },
|
|
129
|
+
)
|
|
130
|
+
.action((options) => {
|
|
131
|
+
console.log(`Forecast for ${options.city}: ${options.days} days`);
|
|
132
|
+
})
|
|
133
|
+
.command('extended', (c) =>
|
|
134
|
+
c
|
|
135
|
+
.options(
|
|
136
|
+
z.object({
|
|
137
|
+
city: z.string().describe('City name'),
|
|
138
|
+
}),
|
|
139
|
+
{ positional: ['city'] },
|
|
140
|
+
)
|
|
141
|
+
.action((options) => {
|
|
142
|
+
console.log(`Extended forecast for ${options.city}`);
|
|
143
|
+
}),
|
|
144
|
+
),
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
// Run nested command
|
|
148
|
+
program.cli('forecast extended London');
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Option Aliases and Metadata
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
const program = createPadrone('app')
|
|
155
|
+
.command('serve', (c) =>
|
|
156
|
+
c
|
|
157
|
+
.options(
|
|
158
|
+
z.object({
|
|
159
|
+
port: z
|
|
160
|
+
.number()
|
|
161
|
+
.default(3000)
|
|
162
|
+
.describe('Port to listen on')
|
|
163
|
+
.meta({ alias: 'p', examples: ['3000', '8080'] }),
|
|
164
|
+
host: z
|
|
165
|
+
.string()
|
|
166
|
+
.default('localhost')
|
|
167
|
+
.describe('Host to bind to')
|
|
168
|
+
.meta({ alias: 'h' }),
|
|
169
|
+
verbose: z
|
|
170
|
+
.boolean()
|
|
171
|
+
.optional()
|
|
172
|
+
.describe('Enable verbose logging')
|
|
173
|
+
.meta({ alias: 'v', deprecated: 'Use --debug instead' }),
|
|
174
|
+
}),
|
|
175
|
+
)
|
|
176
|
+
.action((options) => {
|
|
177
|
+
console.log(`Server running at ${options.host}:${options.port}`);
|
|
178
|
+
}),
|
|
179
|
+
);
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Environment Variables and Config Files
|
|
183
|
+
|
|
184
|
+
Padrone supports binding options to environment variables and config files:
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
const program = createPadrone('app')
|
|
188
|
+
.configure({
|
|
189
|
+
configFiles: ['app.config.json', '.apprc'],
|
|
190
|
+
})
|
|
191
|
+
.command('serve', (c) =>
|
|
192
|
+
c
|
|
193
|
+
.options(
|
|
194
|
+
z.object({
|
|
195
|
+
port: z.number().default(3000).describe('Port to listen on'),
|
|
196
|
+
apiKey: z.string().describe('API key for authentication'),
|
|
197
|
+
}),
|
|
198
|
+
{
|
|
199
|
+
options: {
|
|
200
|
+
port: { env: 'APP_PORT', configKey: 'server.port' },
|
|
201
|
+
apiKey: { env: ['API_KEY', 'APP_API_KEY'] },
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
)
|
|
205
|
+
.action((options) => {
|
|
206
|
+
console.log(`Server running on port ${options.port}`);
|
|
207
|
+
}),
|
|
208
|
+
);
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## π€ AI SDK Integration
|
|
212
|
+
|
|
213
|
+
Padrone provides first-class support for the [Vercel AI SDK](https://ai-sdk.dev/), making it easy to expose your CLI as an AI tool:
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
import { streamText } from 'ai';
|
|
217
|
+
import { createPadrone } from 'padrone';
|
|
218
|
+
import * as z from 'zod/v4';
|
|
219
|
+
|
|
220
|
+
const weatherCli = createPadrone('weather')
|
|
221
|
+
.command('current', (c) =>
|
|
222
|
+
c
|
|
223
|
+
.options(
|
|
224
|
+
z.object({
|
|
225
|
+
city: z.string().describe('City name'),
|
|
226
|
+
}),
|
|
227
|
+
{ positional: ['city'] },
|
|
228
|
+
)
|
|
229
|
+
.action((options) => {
|
|
230
|
+
return { city: options.city, temperature: 72, condition: 'Sunny' };
|
|
231
|
+
}),
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
// Convert your CLI to an AI tool
|
|
235
|
+
const result = await streamText({
|
|
236
|
+
model: yourModel,
|
|
237
|
+
prompt: "What's the weather in London?",
|
|
238
|
+
tools: {
|
|
239
|
+
weather: weatherCli.tool(),
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## π Auto-Generated Help
|
|
245
|
+
|
|
246
|
+
Padrone automatically generates help text from your Zod schemas:
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
console.log(program.help());
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Example output:
|
|
253
|
+
```
|
|
254
|
+
Usage: myapp greet [names...] [options]
|
|
255
|
+
|
|
256
|
+
Arguments:
|
|
257
|
+
names... Names to greet
|
|
258
|
+
|
|
259
|
+
Options:
|
|
260
|
+
-p, --prefix <string> Prefix to use in greeting
|
|
261
|
+
-h, --help Show help
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## π§ API Reference
|
|
265
|
+
|
|
266
|
+
### `createPadrone(name)`
|
|
267
|
+
|
|
268
|
+
Creates a new CLI program with the given name.
|
|
269
|
+
|
|
270
|
+
### Program Methods
|
|
271
|
+
|
|
272
|
+
| Method | Description |
|
|
273
|
+
|--------|-------------|
|
|
274
|
+
| `.configure(config)` | Configure program properties (title, description, version, configFiles) |
|
|
275
|
+
| `.command(name, builder)` | Add a command to the program |
|
|
276
|
+
| `.options(schema, meta?)` | Define options schema with optional positional args |
|
|
277
|
+
| `.action(handler)` | Set the command handler function |
|
|
278
|
+
| `.cli(input?)` | Run as CLI (parses `process.argv` or input string) |
|
|
279
|
+
| `.run(command, options)` | Run a command programmatically |
|
|
280
|
+
| `.parse(input?)` | Parse input without executing |
|
|
281
|
+
| `.stringify(command?, options?)` | Convert command and options back to CLI string |
|
|
282
|
+
| `.api()` | Generate a typed API object |
|
|
283
|
+
| `.help(command?)` | Generate help text |
|
|
284
|
+
| `.tool()` | Generate a Vercel AI SDK tool |
|
|
285
|
+
| `.find(command)` | Find a command by name |
|
|
286
|
+
|
|
287
|
+
### Options Meta
|
|
288
|
+
|
|
289
|
+
Use the second argument of `.options()` to configure positional arguments and per-option metadata:
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
.options(schema, {
|
|
293
|
+
positional: ['source', '...files', 'dest'], // '...files' is variadic
|
|
294
|
+
options: {
|
|
295
|
+
verbose: { alias: 'v', env: 'VERBOSE' },
|
|
296
|
+
config: { configKey: 'settings.config' },
|
|
297
|
+
},
|
|
298
|
+
})
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Zod Meta Options
|
|
302
|
+
|
|
303
|
+
Use `.meta()` on Zod schemas to provide additional CLI metadata:
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
z.string().meta({
|
|
307
|
+
alias: 'p', // Short alias (-p)
|
|
308
|
+
examples: ['value'], // Example values for help text
|
|
309
|
+
deprecated: 'message', // Mark as deprecated
|
|
310
|
+
hidden: true, // Hide from help output
|
|
311
|
+
env: 'MY_VAR', // Bind to environment variable
|
|
312
|
+
configKey: 'path.key', // Bind to config file key
|
|
313
|
+
})
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## π οΈ Requirements
|
|
317
|
+
|
|
318
|
+
- Node.js 18+ or Bun
|
|
319
|
+
- TypeScript 5.0+ (recommended)
|
|
320
|
+
- Zod 3.25+ or 4.x
|
|
321
|
+
|
|
322
|
+
## π License
|
|
323
|
+
|
|
324
|
+
[MIT](LICENSE) Β© [Gokhan Kurt](https://gkurt.com)
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
<p align="center">
|
|
329
|
+
Made with β€οΈ by <a href="https://gkurt.com">Gokhan Kurt</a>
|
|
330
|
+
</p>
|