map-pointer: allow running arbitrary commands

This commit is contained in:
Alexander Courtis
2022-09-13 12:05:21 +10:00
committed by Isaac Freund
parent e2a27b3a4e
commit cacc986166
8 changed files with 89 additions and 25 deletions

View File

@ -434,7 +434,7 @@ pub fn handleSwitchMapping(
}
}
fn runCommand(self: *Self, args: []const [:0]const u8) void {
pub fn runCommand(self: *Self, args: []const [:0]const u8) void {
var out: ?[]const u8 = null;
defer if (out) |s| util.gpa.free(s);
command.run(self, args, &out) catch |err| {
@ -442,7 +442,12 @@ fn runCommand(self: *Self, args: []const [:0]const u8) void {
command.Error.Other => out.?,
else => command.errToMsg(err),
};
std.log.scoped(.command).err("{s}: {s}", .{ args[0], failure_message });
if (args.len == 0) {
std.log.scoped(.command).err("{s}", .{failure_message});
} else {
std.log.scoped(.command).err("{s}: {s}", .{ args[0], failure_message });
}
return;
};
if (out) |s| {