Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl>
---
src/wayprompt-cli.zig | 22 +++-------------------
1 file changed, 3 insertions(+), 19 deletions(-)
diff --git a/src/wayprompt-cli.zig b/src/wayprompt-cli.zig
index 98c2a04..1150827 100644
--- a/src/wayprompt-cli.zig
+++ b/src/wayprompt-cli.zig
@@ -2,6 +2,7 @@ const std = @import("std");
const posix = std.posix;
const mem = std.mem;
const heap = std.heap;
+const argv = std.process.ArgIteratorPosix;
const debug = std.debug;
const io = std.io;
const meta = std.meta;
@@ -156,27 +157,10 @@ fn writeOutput(comptime action: []const u8, pin: ?[]const u8) !void {
try out_buffer.flush();
}
-const FlagIt = struct {
- const Self = @This();
-
- argv: *[][*:0]u8,
- index: usize = 1,
-
- pub fn new(argv: *[][*:0]u8) Self {
- return Self{ .argv = argv };
- }
-
- pub fn next(self: *Self) ?[]const u8 {
- if (self.index >= self.argv.len) return null;
- defer self.index += 1;
- return mem.span(self.argv.*[self.index]);
- }
-};
-
fn parseCmdFlags() !void {
const alloc = arena.allocator();
- var it = FlagIt.new(&std.os.argv);
+ var it = argv.init();
while (it.next()) |flag| {
if (mem.eql(u8, flag, "--title")) {
try dupeArg(alloc, &it, &config.labels.title, "--title");
@@ -231,7 +215,7 @@ fn parseCmdFlags() !void {
}
}
-fn dupeArg(alloc: mem.Allocator, it: *FlagIt, dest: *?[]const u8, comptime flag: []const u8) !void {
+fn dupeArg(alloc: mem.Allocator, it: *argv, dest: *?[]const u8, comptime flag: []const u8) !void {
if (dest.* != null) {
logger.err("redundant '{s}' flag.", .{flag});
return error.RedundantFlag;
--
2.45.2