diff --git a/CHANGELOG.md b/CHANGELOG.md index abdb3d8..b22b320 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v0.9.5 (2025-03-29) +- feat: Added [-v | --version] and [-h | --help] args. + ## v0.9.4 (2025-03-29) - feat: Added keybind `h` to view help / keybind menu. - refactor: `List` drawing logic is now handled by the `Drawer{}`. diff --git a/build.zig b/build.zig index 660740f..54f7667 100644 --- a/build.zig +++ b/build.zig @@ -1,6 +1,9 @@ const std = @import("std"); const builtin = @import("builtin"); +///Must match the `version` in `build.zig.zon`. +const version = std.SemanticVersion{ .major = 0, .minor = 9, .patch = 5 }; + const targets: []const std.Target.Query = &.{ .{ .cpu_arch = .aarch64, .os_tag = .macos }, .{ .cpu_arch = .aarch64, .os_tag = .linux }, @@ -8,7 +11,13 @@ const targets: []const std.Target.Query = &.{ .{ .cpu_arch = .x86_64, .os_tag = .macos }, }; -fn createExe(b: *std.Build, exe_name: []const u8, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !*std.Build.Step.Compile { +fn createExe( + b: *std.Build, + exe_name: []const u8, + target: std.Build.ResolvedTarget, + optimize: std.builtin.OptimizeMode, + build_options: *std.Build.Module, +) !*std.Build.Step.Compile { const libvaxis = b.dependency("vaxis", .{ .target = target }).module("vaxis"); const fuzzig = b.dependency("fuzzig", .{ .target = target }).module("fuzzig"); const zuid = b.dependency("zuid", .{ .target = target }).module("zuid"); @@ -21,6 +30,7 @@ fn createExe(b: *std.Build, exe_name: []const u8, target: std.Build.ResolvedTarg .optimize = optimize, }); + exe.root_module.addImport("options", build_options); exe.root_module.addImport("vaxis", libvaxis); exe.root_module.addImport("fuzzig", fuzzig); exe.root_module.addImport("zuid", zuid); @@ -33,14 +43,19 @@ pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); + const build_options = b.addOptions(); + build_options.step.name = "build options"; + build_options.addOption(std.SemanticVersion, "version", version); + const build_options_module = build_options.createModule(); + // Building targets for release. const build_all = b.option(bool, "all-targets", "Build all targets in ReleaseSafe mode.") orelse false; if (build_all) { - try buildTargets(b); + try buildTargets(b, build_options_module); return; } - const exe = try createExe(b, "jido", target, optimize); + const exe = try createExe(b, "jido", target, optimize, build_options_module); b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); @@ -52,11 +67,11 @@ pub fn build(b: *std.Build) !void { run_step.dependOn(&run_cmd.step); } -fn buildTargets(b: *std.Build) !void { +fn buildTargets(b: *std.Build, build_options: *std.Build.Module) !void { for (targets) |t| { const target = b.resolveTargetQuery(t); - const exe = try createExe(b, "jido", target, .ReleaseSafe); + const exe = try createExe(b, "jido", target, .ReleaseSafe, build_options); b.installArtifact(exe); const target_output = b.addInstallArtifact(exe, .{ diff --git a/build.zig.zon b/build.zig.zon index ce6d90d..33975b5 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,7 +1,7 @@ .{ .name = .jido, .fingerprint = 0xee45eabe36cafb57, - .version = "0.9.4", + .version = "0.9.5", .minimum_zig_version = "0.14.0", .dependencies = .{ diff --git a/src/main.zig b/src/main.zig index 0a96454..3f4c6c6 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,5 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); +const options = @import("options"); const App = @import("app.zig"); const FileLogger = @import("file_logger.zig"); const vaxis = @import("vaxis"); @@ -24,6 +25,29 @@ pub fn main() !void { } const alloc = gpa.allocator(); + var args = std.process.args(); + _ = args.skip(); + if (args.next()) |arg| { + if (std.mem.eql(u8, arg, "--version") or std.mem.eql(u8, arg, "-v")) { + std.debug.print("jido v{}\n", .{options.version}); + return; + } + + if (std.mem.eql(u8, arg, "--help") or std.mem.eql(u8, arg, "-h")) { + std.debug.print( + \\Usage: jido + \\ + \\a lightweight Unix TUI file explorer + \\ + \\Flags: + \\ -h, --help Show help information and exit. + \\ -v, --version Print version information and exit. + \\ + , .{}); + return; + } + } + var app = try App.init(alloc); defer app.deinit();