A simple, extensible command-line interface (CLI) tool written in Zig. This project demonstrates basic CLI functionality including command parsing, option handling, and extensible command structure.
- Command Parsing: Supports multiple commands with clean syntax
- Option Handling: Short (
-n
) and long (--name
) option formats - Extensible Architecture: Easy to add new commands and options
- Error Handling: Comprehensive error handling for various CLI scenarios
- Debug Mode: Optional debug output for development
- Zig 0.15.0 or higher
- Clone or download the project
- Navigate to the project directory
- Build the executable:
zig build
This will create an executable in zig-out/bin/zig-cli
.
You can run the CLI directly using Zig:
zig build run -- [arguments]
Or run the built executable:
./zig-out/bin/zig-cli [arguments]
zig-cli <command> [options]
Greets someone with an optional name.
Options:
-n, --name <value>
: Name to greet (optional, defaults to "World")
Examples:
# Basic greeting
zig-cli hello
# Greeting with a name
zig-cli hello --name Alice
zig-cli hello -n Bob
Output:
Hello, World
Hello, Alice
Hello, Bob
Displays usage information and available commands.
Example:
zig-cli help
Output:
Usage: zig-cli <command> [options]
Commands:
hello Greet someone
help Show this help message
Options for hello:
-n, --name <value> Name to greet
This project has no external dependencies. It uses only the Zig standard library.
src/
├── main.zig # Entry point and command definitions
├── cli.zig # Core CLI parsing and execution logic
└── commands.zig # Command and option implementations
- Add a new command handler in
src/commands.zig
- Register the command in
src/main.zig
in thecommands
array - Update the help command to include the new command
- Add an option handler in
src/commands.zig
- Register the option in
src/main.zig
in theoptions
array - Associate options with commands using the
req
andopt
fields
Run the test suite:
zig build test
-
"Unknown command" error
- Ensure you're using a valid command name
- Check for typos in command names
-
"Unknown option" error
- Verify option syntax (
-n
or--name
) - Ensure options are valid for the specified command
- Verify option syntax (
-
Build errors
- Ensure you have Zig 0.15.0 or higher installed
- Check that all source files are present
Enable debug output by modifying the debug
parameter in src/main.zig
:
try cli.start(&commands, &options, true);
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Ensure all tests pass
- Submit a pull request
This project is open source. Please see individual files for license information.
- Add more built-in commands (e.g., version, config)
- Support for subcommands
- Configuration file support
- Colored output
- Interactive mode
- Plugin system for extending functionality