43 lines
1.1 KiB
Zig
43 lines
1.1 KiB
Zig
const std = @import("std");
|
|
const mem = std.mem;
|
|
const stdout = std.io.getStdOut().writer();
|
|
const process = std.process;
|
|
|
|
const fs = std.fs;
|
|
|
|
pub const warn = std.debug.print;
|
|
pub fn print(comptime format: []const u8, args: anytype) void {
|
|
nosuspend stdout.print(format, args) catch return;
|
|
}
|
|
|
|
pub const CLI = struct {
|
|
const Self = @This();
|
|
|
|
arena: std.heap.ArenaAllocator,
|
|
allocator: std.mem.Allocator,
|
|
args: []const [:0]u8,
|
|
|
|
pub fn init() !Self {
|
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
|
const allocator = arena.allocator();
|
|
var args = try process.argsAlloc(allocator);
|
|
|
|
return Self {
|
|
.arena = arena,
|
|
.allocator = allocator,
|
|
.args = args,
|
|
};
|
|
}
|
|
|
|
pub fn deinit(self: *Self) void {
|
|
self.arena.deinit();
|
|
// process.argsFree(self.allocator, self.args);
|
|
}
|
|
|
|
pub fn nextArg(self: Self, idx: *usize) ?[]const u8 {
|
|
if (idx.* >= self.args.len) return null;
|
|
defer idx.* += 1;
|
|
return self.args[idx.*];
|
|
}
|
|
};
|