mirror of
https://github.com/daylinmorgan/oizys.git
synced 2024-11-05 06:03:15 -06:00
use seperate funtion to get forwarded args
This commit is contained in:
parent
a7302bd609
commit
7dfe185a9f
1 changed files with 17 additions and 14 deletions
|
@ -43,23 +43,26 @@ pub fn init(allocator: Allocator) !Cli {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(self: *Cli) !void {
|
fn get_forward_args(self: *Cli, args: [][]const u8) !usize {
|
||||||
const args = try std.process.argsAlloc(self.allocator);
|
|
||||||
defer std.process.argsFree(self.allocator, args);
|
|
||||||
var forward = std.ArrayList([]const u8).init(self.allocator);
|
var forward = std.ArrayList([]const u8).init(self.allocator);
|
||||||
|
var delim_idx: usize = args.len;
|
||||||
|
|
||||||
// TODO: simplify, this smells
|
|
||||||
const delim_idx = blk: {
|
|
||||||
for (args, 0..) |arg, i|
|
for (args, 0..) |arg, i|
|
||||||
if (std.mem.eql(u8, "--", arg)) {
|
if (std.mem.eql(u8, "--", arg)) {
|
||||||
for (args[i + 1 ..]) |fwd|
|
for (args[i + 1 ..]) |fwd|
|
||||||
try forward.append(try self.allocator.dupe(u8, fwd));
|
try forward.append(try self.allocator.dupe(u8, fwd));
|
||||||
break :blk i;
|
delim_idx = i;
|
||||||
};
|
break;
|
||||||
break :blk args.len;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.forward = try forward.toOwnedSlice();
|
self.forward = try forward.toOwnedSlice();
|
||||||
|
return delim_idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse(self: *Cli) !void {
|
||||||
|
const args = try std.process.argsAlloc(self.allocator);
|
||||||
|
defer std.process.argsFree(self.allocator, args);
|
||||||
|
const delim_idx = try self.get_forward_args(args);
|
||||||
self.matches = try self.app.parseFrom(args[1..delim_idx]);
|
self.matches = try self.app.parseFrom(args[1..delim_idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue