Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: use cova for argument parsing #3

Merged
merged 6 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
[![CI](https://github.com/charlesrocket/xtxf/actions/workflows/ci.yml/badge.svg?branch=trunk)](https://github.com/charlesrocket/xtxf/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/charlesrocket/xtxf/branch/trunk/graph/badge.svg)](https://codecov.io/gh/charlesrocket/xtxf)

## Compilation

```sh
zig build
```

## Usage

```
██ ████
░██ ░██░
Expand All @@ -18,17 +10,16 @@ zig build
░███ ██ ███░ ██
██░██ ░██ ██ ██ ░██
██ ██ ██ ██ ░██ ██
```

## Compilation

Usage: xtxf [OPTIONS]
```sh
zig build
```

Example: xtxf -p -c=red -s=crypto
## Usage

Options:
-c, --color Set color [default, red, green, blue, yellow, magenta]
-s, --style Set style [default, columns, crypto, grid, blocks]
-t, --time Set duration [loop, short]
-p, --pulse Pulse blocks
-d, --decimal Decimal mode
-v, --version Print version
-h, --help Print this message
```sh
xtxf -d -p -c red -s crypto
```
21 changes: 18 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const build_options = b.addOptions();

const exe = b.addExecutable(.{
.name = "xtxf",
Expand All @@ -11,18 +12,27 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});

const ghext_dep = b.dependency("ghext", .{
const cova_dep = b.dependency("cova", .{
.target = target,
.optimize = optimize,
});

const ghext = ghext_dep.module("ghext");
const cova_mod = cova_dep.module("cova");

const cova_gen = @import("cova").addCovaDocGenStep(b, cova_dep, exe, .{
.kinds = &.{.all},
});

const meta_doc_gen = b.step("gen-doc", "Generate Meta Docs");
meta_doc_gen.dependOn(&cova_gen.step);

exe.addIncludePath(b.dependency("termbox2", .{}).path("."));
exe.addCSourceFile(.{ .file = b.path("src/termbox_impl.c") });
exe.linkLibC();
exe.root_module.addImport("ghext", ghext);
exe.root_module.addImport("cova", cova_mod);
exe.root_module.addOptions("build_options", build_options);

build_options.addOption([]const u8, "head_hash", try hash());
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
Expand Down Expand Up @@ -76,3 +86,8 @@ pub fn build(b: *std.Build) void {
const coverage_step = b.step("coverage", "Generate test coverage (kcov)");
coverage_step.dependOn(&merge_step.step);
}

inline fn hash() ![]const u8 {
const gxt = @import("ghext").Ghext.read(std.heap.page_allocator) catch unreachable;
return gxt.hash;
}
8 changes: 6 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
.url = "https://github.com/termbox/termbox2/archive/d4128b49ca4b4c934c5f07b8b7d734421a4a76a0.zip",
.hash = "12200705c160371d843e7a806133f3f803d8da9af8a50c4f43dea7cec3264de1d1c7",
},
.cova = .{
.url = "https://github.com/00JCIV00/cova/archive/b49e22d8f4727a92e86c80932df7a034e5498295.tar.gz",
.hash = "12200ac5cfa52c6ed5df6cbbf6be03f5b5b4a95abe67b750f9f2b0216da11b21e70c",
},
.ghext = .{
.url = "https://github.com/charlesrocket/ghext/archive/refs/tags/0.3.0.tar.gz",
.hash = "12200acee906e217dafde5539a1e5905d093c97b6ba2408e0653772814e3643efc76",
.url = "https://github.com/charlesrocket/ghext/archive/983eac9d280b2db7c7ca9ede2c977815c26b0074.tar.gz",
.hash = "122081d642ad5e81b306b7a0b849b4f9e976f4653468eb18580d2115c3b4654b23b6",
},
},
}
31 changes: 11 additions & 20 deletions src/assets.zig
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
pub const help_message =
\\Usage: xtxf [OPTIONS]
\\ ██ ████
\\ ░██ ░██░
\\ ██ ██ ██████ ██ ██ ██████
\\ ██ ██░ ██░ ░██ ██ ░██
\\ ░███ ██ ███░ ██
\\ ██░██ ░██ ██ ██ ░██
\\ ██ ██ ██ ██ ░██ ██
\\
\\Example: xtxf -p -c=red -s=crypto
\\{s}COMMAND: {s}
\\
\\Options:
\\ -c, --color Set color [default, red, green, blue, yellow, magenta]
\\ -s, --style Set style [default, columns, crypto, grid, blocks]
\\ -t, --time Set duration [loop, short]
\\ -p, --pulse Pulse blocks
\\ -d, --decimal Decimal mode
\\ -v, --version Print version
\\ -h, --help Print this message
;

pub const logo =
\\{s}DESCRIPTION: {s}
\\
\\ ██ ████
\\ ░██ ░██░
\\██ ██ ██████ ██ ██ ██████
\\ ██ ██░ ██░ ░██ ██ ░██
\\ ░███ ██ ███░ ██
\\ ██░██ ░██ ██ ██ ░██
\\██ ██ ██ ██ ░██ ██
\\
;

pub const opt_usage = "{u}{?u}{s} {s}{s?} <{s}:{s}>";
Loading