Skip to content

Commit 40bf0bd

Browse files
authored
The second pre-release (#3)
1 parent d8b1209 commit 40bf0bd

20 files changed

+1300
-532
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,9 @@ uv.lock
9797
*_output.txt
9898
public/
9999
docs/api/
100+
*.o
101+
*.a
102+
*.so
103+
*.dylib
104+
*.dll
105+
*.exe

Makefile

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
################################################################################
2-
# Configuration and Variables
3-
################################################################################
1+
# ################################################################################
2+
# # Configuration and Variables
3+
# ################################################################################
44
ZIG ?= $(shell which zig || echo ~/.local/share/zig/0.14.1/zig)
55
BUILD_TYPE ?= Debug
66
BUILD_OPTS = -Doptimize=$(BUILD_TYPE)
@@ -9,16 +9,13 @@ SRC_DIR := src
99
EXAMPLES_DIR := examples
1010
BUILD_DIR := zig-out
1111
CACHE_DIR := .zig-cache
12-
DOC_SRC := src/lib.zig
13-
DOC_OUT := docs/api/
14-
COVERAGE_DIR := coverage
1512
BINARY_NAME := example
1613
RELEASE_MODE := ReleaseSmall
1714
TEST_FLAGS := --summary all #--verbose
15+
JUNK_FILES := *.o *.obj *.dSYM
1816

1917
# Automatically find all example names
2018
EXAMPLES := $(patsubst %.zig,%,$(notdir $(wildcard examples/*.zig)))
21-
# CHANGED: Default is now "all"
2219
EXAMPLE ?= all
2320

2421
SHELL := /usr/bin/env bash
@@ -28,7 +25,7 @@ SHELL := /usr/bin/env bash
2825
# Targets
2926
################################################################################
3027

31-
.PHONY: all help build rebuild run test release clean lint format doc install-deps coverage setup-hooks test-hooks
28+
.PHONY: all help build rebuild run test release clean lint format docs serve-docs install-deps coverage setup-hooks test-hooks
3229
.DEFAULT_GOAL := help
3330

3431
help: ## Show the help messages for all targets
@@ -48,15 +45,15 @@ rebuild: clean build ## clean and build
4845

4946
run: ## Run an example (e.g. 'make run EXAMPLE=trie' or 'make run' for all)
5047
@if [ "$(EXAMPLE)" = "all" ]; then \
51-
echo "--> Running all examples..."; \
52-
for ex in $(EXAMPLES); do \
53-
echo ""; \
54-
echo "--> Running example: $$ex"; \
55-
$(ZIG) build run-$$ex $(BUILD_OPTS); \
56-
done; \
48+
echo "--> Running all examples..."; \
49+
for ex in $(EXAMPLES); do \
50+
echo ""; \
51+
echo "--> Running example: $$ex"; \
52+
$(ZIG) build run-$$ex $(BUILD_OPTS); \
53+
done; \
5754
else \
58-
echo "--> Running example: $(EXAMPLE)"; \
59-
$(ZIG) build run-$(EXAMPLE) $(BUILD_OPTS); \
55+
echo "--> Running example: $(EXAMPLE)"; \
56+
$(ZIG) build run-$(EXAMPLE) $(BUILD_OPTS); \
6057
fi
6158

6259
test: ## Run tests
@@ -69,7 +66,7 @@ release: ## Build in Release mode
6966

7067
clean: ## Remove docs, build artifacts, and cache directories
7168
@echo "Removing build artifacts, cache, generated docs, and coverage files..."
72-
@rm -rf $(BUILD_DIR) $(CACHE_DIR) $(DOC_OUT) *.profraw $(COVERAGE_DIR) public
69+
@rm -rf $(BUILD_DIR) $(CACHE_DIR) $(JUNK_FILES) docs/api public
7370

7471
lint: ## Check code style and formatting of Zig files
7572
@echo "Running code style checks..."
@@ -79,10 +76,13 @@ format: ## Format Zig files
7976
@echo "Formatting Zig files..."
8077
@$(ZIG) fmt .
8178

82-
doc: ## Generate API documentation
83-
@echo "Generating documentation from $(DOC_SRC) to $(DOC_OUT)..."
84-
@mkdir -p $(DOC_OUT)
85-
@$(ZIG) test $(DOC_SRC) -femit-docs=$(DOC_OUT)
79+
docs: ## Generate API documentation
80+
@echo "Generating API documentation..."
81+
@$(ZIG) build docs
82+
83+
serve-docs: ## Serve the generated documentation on a local server
84+
@echo "Serving documentation at http://localhost:8000..."
85+
@cd docs/api && python3 -m http.server 8000
8686

8787
install-deps: ## Install system dependencies (for Debian-based systems)
8888
@echo "Installing system dependencies..."

README.md

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,85 +13,50 @@
1313
[![Zig Version](https://img.shields.io/badge/Zig-0.14.1-orange?logo=zig&labelColor=282c34)](https://ziglang.org/download/)
1414
[![Release](https://img.shields.io/github/release/habedi/chilli.svg?label=release&style=flat&labelColor=282c34&logo=github)](https://github.com/habedi/chilli/releases/latest)
1515

16-
A mini framework for creating command line applications in Zig
16+
A microframework for creating command-line applications in Zig
1717

1818
</div>
1919

2020
---
2121

22-
Chilli is a lightweight command line interface (CLI) framework for Zig programming language.
22+
Chilli is a lightweight command-line interface (CLI) framework for the Zig programming language.
2323
Its goal is to make it easy to create structured, maintainable, and user-friendly CLIs with minimal boilerplate,
24-
while being small and fast, and not get in the way of your application logic.
24+
while being small and fast, and not getting in the way of your application logic.
2525

26-
> [!IMPORTANT]
27-
> Chilli is in the early stages of development and is not yet ready for serious use.
28-
> The API is not stable and may change without notice.
26+
### Features
2927

30-
### Feature Checklist
28+
- Provides a simple, declarative API for building CLI applications
29+
- Supports nested commands, subcommands, and aliases
30+
- Provides type-safe parsing for flags, positional arguments, and environment variables
31+
- Supports generating automatic `--help` and `--version` output with custom sections
32+
- Uses a shared context to pass application state
33+
- Written in pure Zig with no external dependencies
3134

32-
- [x] **Command Structure**
33-
- [x] Nested commands and subcommands
34-
- [x] Command aliases
35-
- [x] Persistent flags (flags on parent commands are available to children)
36-
37-
- [x] **Argument & Flag Parsing**
38-
- [x] Long flags (`--verbose`), short flags (`-v`), and grouped boolean flags (`-vf`)
39-
- [x] Type-safe flag access (like `ctx.getFlag("count", i64)`)
40-
- [~] Positional Arguments (supports required & optional; no variadic support yet)
41-
42-
- [x] **Help & Usage Output**
43-
- [x] Automatic and context-aware help generation (`--help`)
44-
- [x] Clean, aligned help output for commands, flags, and arguments
45-
- [~] Version display (shows in help text; no automatic `--version` flag)
46-
47-
- [x] **Developer Experience**
48-
- [x] Context data for passing application state
49-
- [ ] Named access for positional arguments (access is currently by index)
50-
- [ ] Deprecation notices for commands or flags
51-
- [ ] Built-in TUI components (like spinners and progress bars)
35+
> [!IMPORTANT]
36+
> Chilli is in early development and is not yet ready for serious use.
37+
> The API is not stable and may change without notice.
38+
> Please use the [issues page](https://github.com/habedi/chilli/issues) to report bugs or request features.
5239
5340
---
5441

5542
### Getting Started
5643

57-
You can use Chilli by adding it as a dependency to your Zig project.
58-
The Zig build system will download and cache it automatically.
44+
You can add Chilli to your project and start using it by following the steps below.
5945

60-
#### 1. Add Chilli to `build.zig.zon`
46+
#### Installation
6147

62-
First, declare the `chilli` dependency in your `build.zig.zon` file.
63-
You will need to provide the URL to a specific release tarball and its content hash.
48+
Run the following command in the root directory of your project to download Chilli:
6449

65-
```zig
66-
.{
67-
.name = "your-cli-app",
68-
.version = "0.1.0",
69-
.minimum_zig_version = "0.14.1",
70-
.dependencies = .{
71-
.chilli = .{
72-
// URL for the latest commit on the main branch
73-
.url = "https://github.com/habedi/chilli/archive/main.tar.gz",
74-
// The hash of that specific commit's content
75-
.hash = "1220...", // Replace with the actual hash
76-
},
77-
},
78-
.paths = .{
79-
"build.zig",
80-
"build.zig.zon",
81-
"src",
82-
},
83-
}
50+
```sh
51+
zig fetch --save=chilli "https://github.com/habedi/chilli/archive/<branch_or_tag>.tar.gz"
8452
```
8553

86-
> [!NOTE]
87-
> To get the correct `.hash` value, you can first put a dummy value (like `"122000"`) and run the `zig build` command.
88-
> The compiler will fail, but it will print the expected hash value for you to copy and paste into the dependencies
89-
> section to replace the dummy value.
54+
Replace `<branch_or_tag>` with the desired branch or tag, like `main` or `v0.1.0`.
55+
This command will download Chilli and add it to Zig's global cache and update your project's `build.zig.zon` file.
9056

91-
#### 2. Use the Dependency in `build.zig`
57+
#### Adding to Build Script
9258

93-
Next, modify your `build.zig` file to get the dependency from the builder and make it available to your executable as a
94-
module.
59+
Next, modify your `build.zig` file to make Chilli available to your build target as a module.
9560

9661
```zig
9762
const std = @import("std");
@@ -120,19 +85,18 @@ pub fn build(b: *std.Build) void {
12085
}
12186
```
12287

123-
#### 3. Write Your Application Code
88+
#### Using Chilli in an Application
12489

125-
Finally, you can `@import("chilli")` and start building your application in `src/main.zig`.
90+
Finally, you can `@import("chilli")` and start using it in your Zig application.
12691

12792
```zig
12893
const std = @import("std");
12994
const chilli = @import("chilli");
13095
13196
// A function for our command to execute
13297
fn greet(ctx: chilli.CommandContext) !void {
133-
// getFlag is type-safe and panics on type mismatch
134-
const name = ctx.getFlag("name", []const u8);
135-
const excitement = ctx.getFlag("excitement", u32);
98+
const name = try ctx.getFlag("name", []const u8);
99+
const excitement = try ctx.getFlag("excitement", u32);
136100
137101
std.print("Hello, {s}", .{name});
138102
var i: u32 = 0;
@@ -159,7 +123,7 @@ pub fn main() anyerror!void {
159123
// Add flags to the command
160124
try root_cmd.addFlag(.{
161125
.name = "name",
162-
.shortcut = "n",
126+
.shortcut = 'n',
163127
.description = "The name to greet",
164128
.type = .String,
165129
.default_value = .{ .String = "World" },
@@ -176,13 +140,54 @@ pub fn main() anyerror!void {
176140
}
177141
```
178142

143+
---
144+
145+
### Documentation
146+
147+
You can use the `make doc` command to generate the API documentation for Chilli.
148+
This will generate HTML documentation in the [docs/api](docs/api/index.html) directory, which you can serve locally with
149+
`make serve-docs` and view in your web browser at `http://localhost:8000/index.html`.
150+
179151
### Examples
180152

181-
| File | Description |
182-
|-------------------------------------------|--------------------------------------------------------------------|
183-
| [simple_cli.zig](examples/simple_cli.zig) | A simple CLI application that shows basic command and flag parsing |
153+
Here’s your table with an added **Index** column:
154+
155+
| **#** | **File** | **Description** |
156+
|-------|-------------------------------------------------------------|---------------------------------------------------------------------|
157+
| 1 | [e1\_simple\_cli.zig](examples/e1_simple_cli.zig) | A simple CLI application that shows basic command and flag parsing |
158+
| 2 | [e2\_nested\_commands.zig](examples/e2_nested_commands.zig) | A CLI application with nested commands and subcommands |
159+
| 3 | [e3\_help\_output.zig](examples/e3_help_output.zig) | Example demonstrates automatic help output and usage information |
160+
| 4 | [e4\_flags\_and\_args.zig](examples/e4_flags_and_args.zig) | Example shows how to use flags and positional arguments in commands |
161+
| 5 | [e5\_custom\_sections.zig](examples/e5_custom_sections.zig) | Example demonstrates grouping subcommands into custom sections |
162+
| 6 | [e6\_advanced\_cli.zig](examples/e6_advanced_cli.zig) | More advanced example that combines multiple features of Chilli |
163+
164+
### Feature Checklist
184165

185-
-----
166+
- [x] **Command Structure**
167+
- [x] Nested commands and subcommands
168+
- [x] Command aliases and single-character shortcuts
169+
- [x] Persistent flags (flags on parent commands are available to children)
170+
171+
- [x] **Argument & Flag Parsing**
172+
- [x] Long flags (`--verbose`), short flags (`-v`), and grouped boolean flags (`-vf`)
173+
- [x] Positional Arguments (supports required, optional, and variadic)
174+
- [x] Type-safe access for flags and arguments (e.g., `ctx.getFlag("count", i64)`)
175+
- [x] Reading flag values from environment variables
176+
177+
- [x] **Help & Usage Output**
178+
- [x] Automatic and context-aware `--help` flag
179+
- [x] Automatic `--version` flag
180+
- [x] Clean, aligned help output for commands, flags, and arguments
181+
- [x] Grouping subcommands into custom sections
182+
183+
- [x] **Developer Experience**
184+
- [x] Simple, declarative API for building commands
185+
- [x] Named access for all flags and arguments
186+
- [x] Shared context data for passing application state
187+
- [ ] Deprecation notices for commands or flags
188+
- [ ] Built-in TUI components (like spinners and progress bars)
189+
190+
---
186191

187192
### Contributing
188193

build.zig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,27 @@ pub fn build(b: *std.Build) void {
2020
.root_source_file = lib_source,
2121
});
2222

23+
// --- Docs Setup ---
24+
const docs_step = b.step("docs", "Generate API documentation");
25+
const doc_install_path = "docs/api";
26+
27+
// Create a command to invoke `zig build-obj -femit-docs`.
28+
// This correctly analyzes the public API of src/lib.zig.
29+
const gen_docs_cmd = b.addSystemCommand(&[_][]const u8{
30+
b.graph.zig_exe, // Use the same zig that is running the build
31+
"build-lib",
32+
"src/lib.zig",
33+
"-femit-docs=" ++ doc_install_path,
34+
});
35+
36+
// Ensure the docs/api directory exists before running the command by running `mkdir -p`
37+
const mkdir_cmd = b.addSystemCommand(&[_][]const u8{
38+
"mkdir", "-p", doc_install_path,
39+
});
40+
gen_docs_cmd.step.dependOn(&mkdir_cmd.step);
41+
42+
docs_step.dependOn(&gen_docs_cmd.step);
43+
2344
// --- Test Setup ---
2445
const lib_unit_tests = b.addTest(.{
2546
.root_source_file = lib_source,

build.zig.zon

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
.{
22
.name = .chilli,
3-
.version = "0.1.0-a1",
3+
.version = "0.1.0-a2",
44
.fingerprint = 0x6c259741ae4f5f73, // Changing this has security and trust implications.
55
.minimum_zig_version = "0.14.1",
6-
.dependencies = .{
7-
// Add dependencies here, for example:
8-
// .{ .name = "some-dependency", .version = "0.1.0" },
9-
},
106
.paths = .{
117
"build.zig",
128
"build.zig.zon",

docs/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)