Refactor keybinding actions reference generation

This commit is contained in:
Bryan Lee
2025-02-12 06:29:40 +08:00
parent 4aa452a2c7
commit 1674224c1a
4 changed files with 120 additions and 69 deletions

View File

@@ -2,7 +2,7 @@ const std = @import("std");
const args = @import("args.zig");
const Action = @import("action.zig").Action;
const Allocator = std.mem.Allocator;
const help_strings = @import("help_strings");
const helpgen_actions = @import("../input/helpgen_actions.zig");
pub const Options = struct {
/// If `true`, print out documentation about the action associated with the
@@ -38,19 +38,7 @@ pub fn run(alloc: Allocator) !u8 {
}
const stdout = std.io.getStdOut().writer();
const info = @typeInfo(help_strings.KeybindAction);
inline for (info.Struct.decls) |field| {
try stdout.print("{s}", .{field.name});
if (opts.docs) {
try stdout.print(":\n", .{});
var iter = std.mem.splitScalar(u8, std.mem.trimRight(u8, @field(help_strings.KeybindAction, field.name), &std.ascii.whitespace), '\n');
while (iter.next()) |line| {
try stdout.print(" {s}\n", .{line});
}
} else {
try stdout.print("\n", .{});
}
}
try helpgen_actions.generate(stdout, .plaintext, opts.docs, std.heap.page_allocator);
return 0;
}