feat: add support for command metadata

This commit is contained in:
CJ van den Berg 2024-09-17 22:57:21 +02:00
parent 6b43dd4f28
commit bdd16f43fb
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
6 changed files with 77 additions and 42 deletions

View file

@ -223,9 +223,12 @@ fn receive_safe(self: *Self, from: tp.pid_ref, m: tp.message) !void {
return;
var cmd: []const u8 = undefined;
var cmd_id: command.ID = undefined;
var ctx: cmds.Ctx = .{};
if (try m.match(.{ "cmd", tp.extract(&cmd) }))
return command.executeName(cmd, ctx) catch |e| self.logger.err(cmd, e);
if (try m.match(.{ "cmd", tp.extract(&cmd_id) }))
return command.execute(cmd_id, ctx) catch |e| self.logger.err("command", e);
var arg: []const u8 = undefined;
@ -233,6 +236,10 @@ fn receive_safe(self: *Self, from: tp.pid_ref, m: tp.message) !void {
ctx.args = .{ .buf = arg };
return command.executeName(cmd, ctx) catch |e| self.logger.err(cmd, e);
}
if (try m.match(.{ "cmd", tp.extract(&cmd_id), tp.extract_cbor(&arg) })) {
ctx.args = .{ .buf = arg };
return command.execute(cmd_id, ctx) catch |e| self.logger.err("command", e);
}
if (try m.match(.{"quit"})) {
project_manager.shutdown();
return;