mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
wip: feat: Migrated version command to zig.
This commit is contained in:
@@ -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
|
// This declares intent for the executable to be installed into the
|
||||||
// install prefix when running `zig build` (i.e. when executing the default
|
// 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
|
// step). By default the install prefix is `zig-out/` but can be overridden
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
.name = .envr,
|
.name = .envr,
|
||||||
// This is a [Semantic Version](https://semver.org/).
|
// This is a [Semantic Version](https://semver.org/).
|
||||||
// In a future version of Zig it will be used for package deduplication.
|
// 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
|
// Together with name, this represents a globally unique package
|
||||||
// identifier. This field is generated by the Zig toolchain when the
|
// identifier. This field is generated by the Zig toolchain when the
|
||||||
// package is first created, and then *never changes*. This allows
|
// package is first created, and then *never changes*. This allows
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ var (
|
|||||||
var long bool
|
var long bool
|
||||||
|
|
||||||
// versionCmd represents the version command
|
// versionCmd represents the version command
|
||||||
|
// Deprecated: Remove when Zig has the chance to emit help
|
||||||
var versionCmd = &cobra.Command{
|
var versionCmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Show envr's version",
|
Short: "Show envr's version",
|
||||||
|
|||||||
28
src/main.zig
28
src/main.zig
@@ -1,6 +1,8 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Io = std.Io;
|
const Io = std.Io;
|
||||||
|
|
||||||
|
const config = @import("config");
|
||||||
|
|
||||||
const envr = @import("envr");
|
const envr = @import("envr");
|
||||||
|
|
||||||
const goBinary = "envr-go";
|
const goBinary = "envr-go";
|
||||||
@@ -11,27 +13,25 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
|
|
||||||
const args = try init.minimal.args.toSlice(arena);
|
const args = try init.minimal.args.toSlice(arena);
|
||||||
|
|
||||||
// if (std.mem.eql(u8, args[1], "version")) {
|
if (args.len > 1 and std.mem.eql(u8, args[1], "version")) {
|
||||||
// version(args[1..]);
|
return version(init.io);
|
||||||
// } else {
|
} else {
|
||||||
return fallbackToGo(init.io, args, arena);
|
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", .{});
|
// std.debug.print("hello from Zig!\n", .{});
|
||||||
|
|
||||||
// for (args[1..]) |arg| {
|
var stdout_buffer: [1024]u8 = undefined;
|
||||||
// std.debug.print("arg: {s}\n", .{arg});
|
var stdout_file_writer: Io.File.Writer = .init(.stdout(), io, &stdout_buffer);
|
||||||
// }
|
const stdout_writer = &stdout_file_writer.interface;
|
||||||
//
|
|
||||||
|
|
||||||
_ = args;
|
try stdout_writer.print("{s}\n", .{config.version});
|
||||||
|
try stdout_writer.flush();
|
||||||
std.debug.print("TODO: Implement\n", .{});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fallbackToGo(
|
fn fallback_to_go(
|
||||||
io: Io,
|
io: Io,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
arena: std.mem.Allocator,
|
arena: std.mem.Allocator,
|
||||||
|
|||||||
Reference in New Issue
Block a user