Function signature
packages/core/src/types.ts:287-295
Parameters
A Standard Schema validation schema. Commonly used with Zod schemas.The schema defines:
- The option’s type (string, number, boolean, etc.)
- Default values
- Validation rules
- Transformations
Optional metadata for the option.
Return value
An option object that can be used in command definitions.
Schema types
Theoption() function works with any Standard Schema implementation. Here are examples using Zod:
String options
Number options
Boolean options
Array options
Enum options
Complex options
Usage in commands
Options are defined in theoptions property of a command:
Command line usage
Options can be passed using different styles:Validation
Options are validated using the provided schema before the handler executes:Using other schema libraries
Since Bunli uses Standard Schema, you can use any compatible validation library:Valibot
Arktype
Type inference
Theoption() function preserves full type information from the schema:
Related
- defineCommand - Define commands with options
- createCLI - Create a CLI instance
- Standard Schema - Universal validation specification