feat: add sample binding of shell_execute_log

This commit is contained in:
CJ van den Berg 2025-01-07 23:08:24 +01:00
parent cfc99b61dc
commit e1f0a4d074
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 18 additions and 12 deletions

View file

@ -607,14 +607,11 @@ const cmds = struct {
if (!try ctx.args.match(.{ tp.string, tp.more }))
return error.InvalidShellArgument;
const cmd = ctx.args;
const handlers = struct {
fn out(_: tp.pid_ref, arg0: []const u8, output: []const u8) void {
const logger = log.logger(arg0);
var it = std.mem.splitScalar(u8, output, '\n');
while (it.next()) |line| logger.print("{s}", .{std.fmt.fmtSliceEscapeLower(line)});
}
};
try shell.execute(self.allocator, cmd, .{ .out = handlers.out });
try shell.execute(self.allocator, cmd, .{
.out = shell.log_handler,
.err = shell.log_err_handler,
.exit = shell.log_exit_err_handler,
});
}
pub const shell_execute_log_meta = .{ .arguments = &.{.string} };