2019-07-08 15:38:16 +00:00
|
|
|
const std = @import("std");
|
|
|
|
const lang = @import("lang.zig");
|
|
|
|
|
|
|
|
pub const RunError = error{UnknownCommand};
|
|
|
|
|
|
|
|
pub const Runner = struct {
|
|
|
|
allocator: *std.mem.Allocator,
|
|
|
|
|
|
|
|
pub fn init(allocator: *std.mem.Allocator) Runner {
|
|
|
|
return Runner{ .allocator = allocator };
|
|
|
|
}
|
|
|
|
|
|
|
|
fn runCommand(self: *Runner, cmd: *lang.Command) !void {
|
|
|
|
return switch (cmd.command) {
|
|
|
|
.Noop => {},
|
|
|
|
else => blk: {
|
|
|
|
std.debug.warn("Unknown command: {}\n", cmd.command);
|
|
|
|
break :blk RunError.UnknownCommand;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-07-08 16:13:03 +00:00
|
|
|
pub fn runCommands(
|
|
|
|
self: *Runner,
|
|
|
|
cmds: lang.CommandList,
|
|
|
|
debug_flag: bool,
|
|
|
|
) !void {
|
2019-07-08 15:38:16 +00:00
|
|
|
var it = cmds.iterator();
|
|
|
|
|
|
|
|
while (it.next()) |cmd| {
|
2019-07-08 16:13:03 +00:00
|
|
|
if (debug_flag) cmd.print();
|
2019-07-08 15:38:16 +00:00
|
|
|
try self.runCommand(cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|