Basic Options
Define options using theoption() helper:
Option Metadata
Theoption() function takes two arguments:
- Schema: A Zod schema for validation and type inference
- Metadata: Configuration object with:
short: Single-character alias (e.g.,-nfor--name)description: Help text for the option
packages/core/src/types.ts:286-295
String Options
examples/task-runner/commands/build.ts:18-27
Boolean Options
Boolean flags toggle features on/off:--watchor-w→true--watch=false→false--no-watch→false(automatic)
examples/hello-world/commands/greet.tsx:69-73, packages/cli/src/commands/build.ts:40-43
Number Options
examples/dev-server/commands/start.ts:9-14, examples/hello-world/commands/greet.tsx:75-79, examples/git-tool/commands/status.ts:37-47
Enum Options
Restrict values to a specific set:examples/task-runner/commands/build.ts:8-16, packages/cli/src/commands/build.ts:52-55
Optional Options
examples/git-tool/commands/status.ts:37-47
Transformations
Transform input values using.transform():
examples/task-runner/commands/build.ts:29-82, packages/cli/src/commands/build.ts:56-63
Complex Validation
Combine multiple validation rules:examples/git-tool/commands/branch.ts:10-20
Type Inference
Bunli automatically infers TypeScript types from your schemas:Accessing Options
Options are available in theflags object:
Positional Arguments
Capture arguments that aren’t flags:Passthrough Arguments
Use-- to pass arguments directly:
packages/core/src/cli.ts:675-679
Validation Errors
Zod provides detailed error messages:packages/core/src/cli.ts:465-483
Standard Schema Support
Bunli uses Standard Schema, which means any schema library that implements the spec will work:packages/core/src/types.ts:1-3
Next Steps
Defining Commands
Learn the fundamentals of command creation
Command Groups
Organize commands into nested hierarchies
Type Generation
Automatic type inference for your commands
Building Binaries
Compile your CLI to standalone executables