feat: support command arguments in run_async
This commit is contained in:
parent
22edc62874
commit
e861bcecbe
1 changed files with 38 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const tp = @import("thespian");
|
const tp = @import("thespian");
|
||||||
|
const cbor = @import("cbor");
|
||||||
const log = @import("log");
|
const log = @import("log");
|
||||||
const config = @import("config");
|
const config = @import("config");
|
||||||
const project_manager = @import("project_manager");
|
const project_manager = @import("project_manager");
|
||||||
|
@ -817,11 +818,44 @@ const cmds = struct {
|
||||||
}
|
}
|
||||||
pub const open_keybind_config_meta = .{ .description = "Edit key bindings" };
|
pub const open_keybind_config_meta = .{ .description = "Edit key bindings" };
|
||||||
|
|
||||||
pub fn run_async(_: *Self, ctx: Ctx) Result {
|
pub fn run_async(self: *Self, ctx: Ctx) Result {
|
||||||
var cmd: []const u8 = undefined;
|
var iter = ctx.args.buf;
|
||||||
if (!try ctx.args.match(.{tp.extract(&cmd)}))
|
var len = try cbor.decodeArrayHeader(&iter);
|
||||||
|
if (len < 1)
|
||||||
return tp.exit_error(error.InvalidArgument, null);
|
return tp.exit_error(error.InvalidArgument, null);
|
||||||
try tp.self_pid().send(.{ "cmd", cmd, .{} });
|
|
||||||
|
var cmd: []const u8 = undefined;
|
||||||
|
if (!try cbor.matchValue(&iter, cbor.extract(&cmd)))
|
||||||
|
return tp.exit_error(error.InvalidArgument, null);
|
||||||
|
len -= 1;
|
||||||
|
|
||||||
|
var args = std.ArrayList([]const u8).init(self.allocator);
|
||||||
|
defer args.deinit();
|
||||||
|
while (len > 0) : (len -= 1) {
|
||||||
|
var arg: []const u8 = undefined;
|
||||||
|
if (try cbor.matchValue(&iter, cbor.extract_cbor(&arg))) {
|
||||||
|
try args.append(arg);
|
||||||
|
} else return tp.exit_error(error.InvalidArgument, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
var args_cb = std.ArrayList(u8).init(self.allocator);
|
||||||
|
defer args_cb.deinit();
|
||||||
|
{
|
||||||
|
const writer = args_cb.writer();
|
||||||
|
try cbor.writeArrayHeader(writer, args.items.len);
|
||||||
|
for (args.items) |arg| try writer.writeAll(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
var msg_cb = std.ArrayList(u8).init(self.allocator);
|
||||||
|
defer msg_cb.deinit();
|
||||||
|
{
|
||||||
|
const writer = msg_cb.writer();
|
||||||
|
try cbor.writeArrayHeader(writer, 3);
|
||||||
|
try cbor.writeValue(writer, "cmd");
|
||||||
|
try cbor.writeValue(writer, cmd);
|
||||||
|
try writer.writeAll(args_cb.items);
|
||||||
|
}
|
||||||
|
try tp.self_pid().send_raw(.{ .buf = msg_cb.items });
|
||||||
}
|
}
|
||||||
pub const run_async_meta = .{ .interactive = false };
|
pub const run_async_meta = .{ .interactive = false };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue