Skip to content

Commit 8860b11

Browse files
authored
The second revision (#8)
1 parent 4d76a33 commit 8860b11

20 files changed

+154
-129
lines changed

.github/workflows/lints.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: Run Linter Checks
22

33
on:
44
push:
5-
branches:
6-
- main
75
tags:
86
- 'v*'
97

.github/workflows/tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: Run Tests
22

33
on:
44
push:
5-
branches:
6-
- main
75
tags:
86
- 'v*'
97

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
default_stages: [ pre-push ]
2+
fail_fast: false
23

34
repos:
45
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -39,4 +40,3 @@ repos:
3940
entry: make test
4041
language: system
4142
pass_filenames: false
42-
stages: [ pre-push ]

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Code of Conduct
1+
## Code of Conduct
22

33
We adhere to the [Contributor Covenant](https://www.contributor-covenant.org/version/2/1/code_of_conduct/) version 2.1.

CONTRIBUTING.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
# Contribution Guidelines
1+
## Contribution Guidelines
22

33
Thank you for considering contributing to this project!
44
Contributions are always welcome and appreciated.
55

6-
## How to Contribute
6+
### How to Contribute
77

88
Please check the [issue tracker](https://github.com/habedi/chilli/issues) to see if there is an issue you
99
would like to work on or if it has already been resolved.
1010

11-
### Reporting Bugs
11+
#### Reporting Bugs
1212

1313
1. Open an issue on the [issue tracker](https://github.com/habedi/chilli/issues).
1414
2. Include information such as steps to reproduce the observed behavior and relevant logs or screenshots.
1515

16-
### Suggesting Features
16+
#### Suggesting Features
1717

1818
1. Open an issue on the [issue tracker](https://github.com/habedi/chilli/issues).
1919
2. Provide details about the feature, its purpose, and potential implementation ideas.
2020

21-
## Submitting Pull Requests
21+
### Submitting Pull Requests
2222

23-
- Ensure all tests pass before submitting a pull request.
23+
- Make sure all tests pass before submitting a pull request.
2424
- Write a clear description of the changes you made and the reasons behind them.
2525

2626
> [!IMPORTANT]
2727
> It's assumed that by submitting a pull request, you agree to license your contributions under the project's license.
2828
29-
## Development Workflow
29+
### Development Workflow
3030

31-
### Prerequisites
31+
#### Prerequisites
3232

3333
Install GNU Make on your system if it's not already installed.
3434

@@ -39,22 +39,22 @@ sudo apt-get install make
3939

4040
- Use the `make install-deps` command to install the development dependencies.
4141

42-
### Code Style
42+
#### Code Style
4343

4444
- Use the `make format` command to format the code.
4545

46-
### Running Tests
46+
#### Running Tests
4747

4848
- Use the `make test` command to run the tests.
4949

50-
### Running Linters
50+
#### Running Linters
5151

5252
- Use the `make lint` command to run the linters.
5353

54-
### See Available Commands
54+
#### See Available Commands
5555

5656
- Run `make help` to see all available commands for managing different tasks.
5757

58-
## Code of Conduct
58+
### Code of Conduct
5959

60-
We adhere to the [Contributor Covenant](https://www.contributor-covenant.org/version/2/1/code_of_conduct/) version 2.1.
60+
We adhere to the project's [Code of Conduct](CODE_OF_CONDUCT.md).

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ help: ## Show the help messages for all targets
3535
@grep -E '^[a-zA-Z_-]+:.*## .*$$' Makefile | \
3636
awk 'BEGIN {FS = ":.*## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
3737

38-
all: build test lint doc ## build, test, lint, and doc
38+
all: build test lint docs ## build, test, lint, and doc
3939

4040
build: ## Build project (Mode=$(BUILD_TYPE))
4141
@echo "Building project in $(BUILD_TYPE) mode with $(JOBS) concurrent jobs..."
4242
@$(ZIG) build $(BUILD_OPTS) -j$(JOBS)
4343

4444
rebuild: clean build ## clean and build
4545

46-
run: ## Run an example (e.g. 'make run EXAMPLE=trie' or 'make run' for all)
46+
run: ## Run an example (e.g. 'make run EXAMPLE=e1_simple_cli' or 'make run' for all)
4747
@if [ "$(EXAMPLE)" = "all" ]; then \
4848
echo "--> Running all examples..."; \
4949
for ex in $(EXAMPLES); do \

README.md

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
[![Tests](https://img.shields.io/github/actions/workflow/status/habedi/chilli/tests.yml?label=tests&style=flat&labelColor=282c34&logo=github)](https://github.com/habedi/chilli/actions/workflows/tests.yml)
1010
[![CodeFactor](https://img.shields.io/codefactor/grade/github/habedi/chilli?label=code%20quality&style=flat&labelColor=282c34&logo=codefactor)](https://www.codefactor.io/repository/github/habedi/chilli)
11-
[![Zig Version](https://img.shields.io/badge/Zig-0.14.1-orange?logo=zig&labelColor=282c34)](https://ziglang.org/download/)
12-
[![Docs](https://img.shields.io/github/v/tag/habedi/chilli?label=docs&color=blue&style=flat&labelColor=282c34&logo=read-the-docs)](https://habedi.github.io/chilli/)
13-
[![Examples](https://img.shields.io/github/v/tag/habedi/chilli?label=examples&color=green&style=flat&labelColor=282c34&logo=zig)](https://github.com/habedi/chilli/tree/main/examples)
11+
[![Zig Version](https://img.shields.io/badge/Zig-0.15.1-orange?logo=zig&labelColor=282c34)](https://ziglang.org/download/)
12+
[![Docs](https://img.shields.io/badge/docs-view-blue?style=flat&labelColor=282c34&logo=read-the-docs)](https://habedi.github.io/chilli/)
13+
[![Examples](https://img.shields.io/badge/examples-view-green?style=flat&labelColor=282c34&logo=zig)](https://github.com/habedi/chilli/tree/main/examples)
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
[![License](https://img.shields.io/badge/license-MIT-007ec6?label=license&style=flat&labelColor=282c34&logo=open-source-initiative)](https://github.com/habedi/chilli/blob/main/LICENSE)
1616

@@ -47,7 +47,8 @@ Run the following command in the root directory of your project to download Chil
4747
zig fetch --save=chilli "https://github.com/habedi/chilli/archive/<branch_or_tag>.tar.gz"
4848
```
4949

50-
Replace `<branch_or_tag>` with the desired branch or tag, like `main` or `v0.1.0`.
50+
Replace `<branch_or_tag>` with the desired branch or tag, like `main` (for the development version) or `v0.2.0`
51+
(for the latest release).
5152
This command will download Chilli and add it to Zig's global cache and update your project's `build.zig.zon` file.
5253

5354
#### Adding to Build Script
@@ -61,21 +62,25 @@ pub fn build(b: *std.Build) void {
6162
const target = b.standardTargetOptions(.{});
6263
const optimize = b.standardOptimizeOption(.{});
6364
64-
const exe = b.addExecutable(.{
65-
.name = "your-cli-app",
66-
.root_source_file = b.path("src/main.zig"),
67-
.target = target,
68-
.optimize = optimize,
69-
});
70-
7165
// 1. Get the dependency object from the builder
7266
const chilli_dep = b.dependency("chilli", .{});
7367
74-
// 2. Get chilli's top-level module
68+
// 2. Create a module for the dependency
7569
const chilli_module = chilli_dep.module("chilli");
7670
77-
// 3. Add the module to your executable so you can @import("chilli")
78-
exe.root_module.addImport("chilli", chilli_module);
71+
// 3. Create your executable module and add chilli as import
72+
const exe_module = b.createModule(.{
73+
.root_source_file = b.path("src/main.zig"),
74+
.target = target,
75+
.optimize = optimize,
76+
});
77+
exe_module.addImport("chilli", chilli_module);
78+
79+
// 4. Create executable with the module
80+
const exe = b.addExecutable(.{
81+
.name = "your-cli-app",
82+
.root_module = exe_module,
83+
});
7984
8085
b.installArtifact(exe);
8186
}
@@ -136,6 +141,23 @@ pub fn main() anyerror!void {
136141
}
137142
```
138143

144+
You can now run your CLI application with the `--help` flag to see the output below:
145+
146+
```bash
147+
$ ./your-cli-app --help
148+
your-cli-app v0.2.0
149+
A new CLI built with Chilli
150+
151+
USAGE:
152+
your-cli-app [FLAGS]
153+
154+
FLAGS:
155+
-n, --name <string> The name to greet [default: World]
156+
--excitement <int> How excited to be [default: 1]
157+
-h, --help Prints help information
158+
-V, --version Prints version information
159+
```
160+
139161
---
140162

141163
### Documentation
@@ -147,12 +169,9 @@ from the source code.
147169
This will generate HTML documentation in the `docs/api` directory, which you can serve locally with `make serve-docs`
148170
and view in your web browser at [http://localhost:8000](http://localhost:8000).
149171

150-
> [!NOTE]
151-
> To generate the documentation, you need to have Zig (version 0.14.1) and Python 3 installed on your system.
152-
153172
### Examples
154173

155-
Check out the [examples](examples/README.md) directory for examples of how Chilli can be used to build a variety of CLI
174+
Check out the [examples](examples/) directory for examples of how Chilli can be used to build a variety of CLI
156175
applications.
157176

158177
### Feature Roadmap

build.zig

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,23 @@ pub fn build(b: *std.Build) void {
88
// --- Library Setup ---
99
const lib_source = b.path("src/lib.zig");
1010

11-
const lib = b.addStaticLibrary(.{
12-
.name = "chilli",
11+
const lib_module = b.createModule(.{
1312
.root_source_file = lib_source,
1413
.target = target,
1514
.optimize = optimize,
1615
});
16+
17+
const lib = b.addLibrary(.{
18+
.name = "chilli",
19+
.root_module = lib_module,
20+
});
1721
b.installArtifact(lib);
1822

19-
const lib_module = b.createModule(.{
23+
// Export the module so downstream projects can use it
24+
_ = b.addModule("chilli", .{
2025
.root_source_file = lib_source,
26+
.target = target,
27+
.optimize = optimize,
2128
});
2229

2330
// --- Docs Setup ---
@@ -39,12 +46,16 @@ pub fn build(b: *std.Build) void {
3946
docs_step.dependOn(&gen_docs_cmd.step);
4047

4148
// --- Test Setup ---
42-
const lib_unit_tests = b.addTest(.{
49+
const test_module = b.createModule(.{
4350
.root_source_file = lib_source,
4451
.target = target,
4552
.optimize = optimize,
4653
});
4754

55+
const lib_unit_tests = b.addTest(.{
56+
.root_module = test_module,
57+
});
58+
4859
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
4960
const test_step = b.step("test", "Run unit tests");
5061
test_step.dependOn(&run_lib_unit_tests.step);
@@ -61,13 +72,17 @@ pub fn build(b: *std.Build) void {
6172
const exe_name = fs.path.stem(entry.name);
6273
const exe_path = b.fmt("{s}/{s}", .{ examples_path, entry.name });
6374

64-
const exe = b.addExecutable(.{
65-
.name = exe_name,
75+
const exe_module = b.createModule(.{
6676
.root_source_file = b.path(exe_path),
6777
.target = target,
6878
.optimize = optimize,
6979
});
70-
exe.root_module.addImport("chilli", lib_module);
80+
exe_module.addImport("chilli", lib_module);
81+
82+
const exe = b.addExecutable(.{
83+
.name = exe_name,
84+
.root_module = exe_module,
85+
});
7186
b.installArtifact(exe);
7287

7388
const run_cmd = b.addRunArtifact(exe);

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Chilli's Examples
1+
## Chilli Examples
22

33
| **#** | **File** | **Description** |
44
|-------|--------------------------------------------------|-----------------------------------------------------------------------------|

examples/e1_simple_cli.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn main() anyerror!void {
6060
fn rootExec(ctx: chilli.CommandContext) anyerror!void {
6161
const app_ctx = ctx.getContextData(AppContext).?;
6262
const config_slice = try ctx.getFlag("config", []const u8);
63-
const stdout = std.io.getStdOut().writer();
63+
const stdout = std.fs.File.stdout().deprecatedWriter();
6464

6565
if (app_ctx.config_path.len > 0) {
6666
ctx.app_allocator.free(app_ctx.config_path);
@@ -75,7 +75,7 @@ fn rootExec(ctx: chilli.CommandContext) anyerror!void {
7575
fn runExec(ctx: chilli.CommandContext) anyerror!void {
7676
const task_name = try ctx.getArg("task-name", []const u8);
7777
const files = ctx.getArgs("files");
78-
const stdout = std.io.getStdOut().writer();
78+
const stdout = std.fs.File.stdout().deprecatedWriter();
7979

8080
try stdout.print("Running task '{s}'...\n", .{task_name});
8181

0 commit comments

Comments
 (0)