allow args to be deinited on error, fix argAt

This commit is contained in:
Luna 2019-12-02 20:13:19 -03:00
parent 46d576fc13
commit 09471e564a
1 changed files with 5 additions and 2 deletions

View File

@ -45,13 +45,14 @@ pub const Command = struct {
}
pub fn argAt(self: Command, idx: usize) ![]const u8 {
const args = self.args.toSliceConst();
std.debug.warn("{} {}", idx, self.args.len);
if (idx > (args.len - 1)) {
if (idx > (self.args.len - 1)) {
std.debug.warn("Expected argument at index {}\n", idx);
return ParseError.ArgRequired;
}
const args = self.args.toSliceConst();
return args[idx];
}
@ -361,6 +362,8 @@ pub const Lang = struct {
}
var args = ArgList.init(self.allocator);
errdefer args.deinit();
while (tok_it.next()) |arg| {
try args.append(arg);
}