gpower2/src/action.zig
2022-05-26 20:15:52 +02:00

29 lines
771 B
Zig

const std = @import("std");
const cfg = @import("config.zig");
pub const Action = enum {
shutdown,
reboot,
@"suspend",
hibernate,
pub fn execute(
self: Action,
handle_out: *?*std.ChildProcess,
alloc: std.mem.Allocator,
) !void {
std.log.info("Executing action {s}", .{@tagName(self)});
const argv = switch (self) {
.shutdown => cfg.global_config.?.shutdown_command,
.reboot => cfg.global_config.?.reboot_command,
.@"suspend" => cfg.global_config.?.suspend_command,
.hibernate => cfg.global_config.?.hibernate_command,
};
var child = try std.ChildProcess.init(argv, alloc);
try child.spawn();
handle_out.* = child;
}
};