Generate help strings for keybind actions.

This commit is contained in:
Jeffrey C. Ollie
2024-01-21 19:47:36 -06:00
parent d96c2e7507
commit cab28c3940

View File

@ -6,6 +6,7 @@ const std = @import("std");
const ziglyph = @import("ziglyph");
const Config = @import("config/Config.zig");
const Action = @import("cli/action.zig").Action;
const KeybindAction = @import("input/Binding.zig").Action;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
@ -20,6 +21,7 @@ pub fn main() !void {
try genConfig(alloc, stdout);
try genActions(alloc, stdout);
try genKeybindActions(alloc, stdout);
}
fn genConfig(alloc: std.mem.Allocator, writer: anytype) !void {
@ -114,6 +116,25 @@ fn genActions(alloc: std.mem.Allocator, writer: anytype) !void {
try writer.writeAll("};\n");
}
fn genKeybindActions(alloc: std.mem.Allocator, writer: anytype) !void {
var ast = try std.zig.Ast.parse(alloc, @embedFile("input/Binding.zig"), .zig);
defer ast.deinit(alloc);
try writer.writeAll(
\\/// keybind actions help
\\pub const KeybindAction = struct {
\\
\\
);
inline for (@typeInfo(KeybindAction).Union.fields) |field| {
if (field.name[0] == '_') continue;
try genConfigField(alloc, writer, ast, field.name);
}
try writer.writeAll("};\n");
}
fn extractDocComments(
alloc: std.mem.Allocator,
ast: std.zig.Ast,