Skip to content

Commit 470f9db

Browse files
Merge pull request #9 from effect-native/release/v0.2.0
feat: add --version and --help CLI flags, bump to v0.2.0
2 parents 5db2e2c + d6ebcee commit 470f9db

File tree

4 files changed

+92
-18
lines changed

4 files changed

+92
-18
lines changed

build.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const std = @import("std");
22

3+
const version = "0.2.0";
4+
35
// Although this function looks imperative, it does not perform the build
46
// directly and instead it mutates the build graph (`b`) that will be then
57
// executed by an external runner. The functions in `std.Build` implement a DSL
@@ -77,6 +79,10 @@ pub fn build(b: *std.Build) void {
7779
//
7880
// If neither case applies to you, feel free to delete the declaration you
7981
// don't need and to put everything under a single module.
82+
// Create build options module to pass version to the executable
83+
const build_options = b.addOptions();
84+
build_options.addOption([]const u8, "version", version);
85+
8086
const exe = b.addExecutable(.{
8187
.name = "ansilust",
8288
.root_module = b.createModule(.{
@@ -100,6 +106,7 @@ pub fn build(b: *std.Build) void {
100106
// importing modules from different packages).
101107
.{ .name = "ansilust", .module = mod },
102108
.{ .name = "parsers", .module = parsers_mod },
109+
.{ .name = "build_options", .module = build_options.createModule() },
103110
},
104111
}),
105112
});

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
.name = .ansilust,
1010
// This is a [Semantic Version](https://semver.org/).
1111
// In a future version of Zig it will be used for package deduplication.
12-
.version = "0.0.0",
12+
.version = "0.2.0",
1313
// Together with name, this represents a globally unique package
1414
// identifier. This field is generated by the Zig toolchain when the
1515
// package is first created, and then *never changes*. This allows

packages/ansilust/package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ansilust",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Next-generation text art processing system - convert, render, and animate ANSI art",
55
"main": "index.js",
66
"bin": {
@@ -26,16 +26,16 @@
2626
"detect-libc": "^2.1.2"
2727
},
2828
"optionalDependencies": {
29-
"ansilust-darwin-arm64": "0.0.1",
30-
"ansilust-darwin-x64": "0.0.1",
31-
"ansilust-linux-aarch64-gnu": "0.0.1",
32-
"ansilust-linux-aarch64-musl": "0.0.1",
33-
"ansilust-linux-arm-gnu": "0.0.1",
34-
"ansilust-linux-arm-musl": "0.0.1",
35-
"ansilust-linux-i386-musl": "0.0.1",
36-
"ansilust-linux-x64-gnu": "0.0.1",
37-
"ansilust-linux-x64-musl": "0.0.1",
38-
"ansilust-win32-x64": "0.0.1"
29+
"ansilust-darwin-arm64": "0.2.0",
30+
"ansilust-darwin-x64": "0.2.0",
31+
"ansilust-linux-aarch64-gnu": "0.2.0",
32+
"ansilust-linux-aarch64-musl": "0.2.0",
33+
"ansilust-linux-arm-gnu": "0.2.0",
34+
"ansilust-linux-arm-musl": "0.2.0",
35+
"ansilust-linux-i386-musl": "0.2.0",
36+
"ansilust-linux-x64-gnu": "0.2.0",
37+
"ansilust-linux-x64-musl": "0.2.0",
38+
"ansilust-win32-x64": "0.2.0"
3939
},
4040
"engines": {
4141
"node": ">=14.0.0"

src/main.zig

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
const std = @import("std");
22
const ansilust = @import("ansilust");
3+
const build_options = @import("build_options");
4+
5+
const version = build_options.version;
6+
7+
// Helper for managed ArrayList in Zig 0.15
8+
fn ArrayList(comptime T: type) type {
9+
return std.array_list.AlignedManaged(T, null);
10+
}
11+
12+
fn printVersion() void {
13+
const stdout_file = std.fs.File{ .handle = std.posix.STDOUT_FILENO };
14+
stdout_file.writeAll("ansilust " ++ version ++ "\n") catch {};
15+
}
16+
17+
fn printHelp(file: std.fs.File) void {
18+
file.writeAll(
19+
\\ansilust - Next-generation text art processing system
20+
\\
21+
\\USAGE:
22+
\\ ansilust [OPTIONS] <file.ans> [<file2.ans> ...]
23+
\\
24+
\\OPTIONS:
25+
\\ -h, --help Print this help message
26+
\\ -V, --version Print version information
27+
\\
28+
\\EXAMPLES:
29+
\\ ansilust artwork.ans Render ANSI art to terminal
30+
\\ ansilust file1.ans file2.ans Render multiple files
31+
\\
32+
) catch {};
33+
}
334

435
fn processFile(allocator: std.mem.Allocator, path: []const u8) !void {
536
const file_data = std.fs.cwd().readFileAlloc(allocator, path, 100 * 1024 * 1024) catch |e| {
@@ -34,14 +65,50 @@ pub fn main() !void {
3465

3566
_ = args.next(); // skip argv0
3667

37-
var file_count: usize = 0;
38-
while (args.next()) |path| {
39-
try processFile(allocator, path);
40-
file_count += 1;
68+
const stdout_file = std.fs.File{ .handle = std.posix.STDOUT_FILENO };
69+
const stderr_file = std.fs.File{ .handle = std.posix.STDERR_FILENO };
70+
71+
var file_paths = ArrayList([]const u8).init(allocator);
72+
defer file_paths.deinit();
73+
74+
var show_help = false;
75+
var show_version = false;
76+
77+
// Parse all arguments first, collect file paths
78+
while (args.next()) |arg| {
79+
if (std.mem.eql(u8, arg, "-h") or std.mem.eql(u8, arg, "--help")) {
80+
show_help = true;
81+
} else if (std.mem.eql(u8, arg, "-V") or std.mem.eql(u8, arg, "--version")) {
82+
show_version = true;
83+
} else if (std.mem.startsWith(u8, arg, "-")) {
84+
var buf: [256]u8 = undefined;
85+
const msg = std.fmt.bufPrint(&buf, "error: unknown option '{s}'\n", .{arg}) catch "error: unknown option\n";
86+
stderr_file.writeAll(msg) catch {};
87+
stderr_file.writeAll("Try 'ansilust --help' for more information.\n") catch {};
88+
std.process.exit(1);
89+
} else {
90+
try file_paths.append(arg);
91+
}
92+
}
93+
94+
// Handle flags before processing files
95+
if (show_version) {
96+
printVersion();
97+
return;
4198
}
4299

43-
if (file_count == 0) {
44-
std.debug.print("usage: ansilust <file.ans> [<file2.ans> ...]\n", .{});
100+
if (show_help) {
101+
printHelp(stdout_file);
45102
return;
46103
}
104+
105+
if (file_paths.items.len == 0) {
106+
printHelp(stderr_file);
107+
std.process.exit(1);
108+
}
109+
110+
// Process files after all argument parsing is complete
111+
for (file_paths.items) |path| {
112+
try processFile(allocator, path);
113+
}
47114
}

0 commit comments

Comments
 (0)