wip: feat: Migrated version command to zig.

This commit is contained in:
2026-04-17 16:42:15 -04:00
parent ce135e9ce4
commit 43b03e0aca
5 changed files with 24 additions and 15 deletions

1
.gitignore vendored
View File

@@ -12,4 +12,5 @@ man
.zig-cache
builds
envr
envr-go
result

View File

@@ -83,6 +83,13 @@ pub fn build(b: *std.Build) void {
}),
});
const version = b.option([]const u8, "version", "application version string") orelse "dev";
const options = b.addOptions();
options.addOption([]const u8, "version", version);
exe.root_module.addOptions("config", options);
// This declares intent for the executable to be installed into the
// install prefix when running `zig build` (i.e. when executing the default
// step). By default the install prefix is `zig-out/` but can be overridden

View File

@@ -9,7 +9,7 @@
.name = .envr,
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.version = "0.3.0",
// Together with name, this represents a globally unique package
// identifier. This field is generated by the Zig toolchain when the
// package is first created, and then *never changes*. This allows

View File

@@ -15,6 +15,7 @@ var (
var long bool
// versionCmd represents the version command
// Deprecated: Remove when Zig has the chance to emit help
var versionCmd = &cobra.Command{
Use: "version",
Short: "Show envr's version",

View File

@@ -1,6 +1,8 @@
const std = @import("std");
const Io = std.Io;
const config = @import("config");
const envr = @import("envr");
const goBinary = "envr-go";
@@ -11,27 +13,25 @@ pub fn main(init: std.process.Init) !void {
const args = try init.minimal.args.toSlice(arena);
// if (std.mem.eql(u8, args[1], "version")) {
// version(args[1..]);
// } else {
return fallbackToGo(init.io, args, arena);
// }
if (args.len > 1 and std.mem.eql(u8, args[1], "version")) {
return version(init.io);
} else {
return fallback_to_go(init.io, args, arena);
}
}
fn version(args: []const [:0]const u8) void {
fn version(io: Io) !void {
// std.debug.print("hello from Zig!\n", .{});
// for (args[1..]) |arg| {
// std.debug.print("arg: {s}\n", .{arg});
// }
//
var stdout_buffer: [1024]u8 = undefined;
var stdout_file_writer: Io.File.Writer = .init(.stdout(), io, &stdout_buffer);
const stdout_writer = &stdout_file_writer.interface;
_ = args;
std.debug.print("TODO: Implement\n", .{});
try stdout_writer.print("{s}\n", .{config.version});
try stdout_writer.flush();
}
fn fallbackToGo(
fn fallback_to_go(
io: Io,
args: []const [:0]const u8,
arena: std.mem.Allocator,