Handler Function
Define a handler in your command:Handler Signature
Handlers receive a single argument with the following type:Handler Context
TheHandlerArgs object provides everything needed to implement your command:
Parsed Options
Parsed and validated command options with full type inference.
Positional arguments passed after options.
Shell Execution
Bun Shell for executing commands. Provides template literal syntax with automatic escaping.
Environment
Process environment variables.
Current working directory.
Terminal Utilities
Interactive prompts for user input.
Create animated spinners for long-running operations.
Terminal color utilities from
@bunli/utils.Terminal Information
Information about the terminal environment.
Runtime Information
Runtime execution context.
Interrupt Handling
Signal for cooperative cancellation (Ctrl+C handling).
Plugin Context
Plugin context with shared store (available when plugins are loaded).
Async Handlers
All handlers are async and can useawait:
Error Handling in Handlers
Handlers can throw errors which are caught by Bunli:- Basic Errors
- Validation Errors
- Custom Errors
Working with Shell Commands
Theshell utility provides safe command execution:
Interactive Prompts
Create interactive command experiences:Progress Indication
Provide feedback for long-running operations:Type-Safe Flags
Bunli automatically infers flag types from options:Best Practices
See Also
- Commands - Define CLI commands
- Options - Define command options
- Error Handling - Handle errors gracefully
- Prompts API - Interactive prompt utilities