|
| 1 | +const std = @import("std"); |
| 2 | +const Action = @import("../../cli/action.zig").Action; |
| 3 | +const help_strings = @import("help_strings"); |
| 4 | + |
| 5 | +pub fn main() !void { |
| 6 | + const output = std.io.getStdOut().writer(); |
| 7 | + try genActions(output); |
| 8 | +} |
| 9 | + |
| 10 | +// Note: as a shortcut for defining inline editOnGithubLinks per cli action the user |
| 11 | +// is directed to the folder view on Github. This includes a README pointing them to |
| 12 | +// the files to edit. |
| 13 | +pub fn genActions(writer: anytype) !void { |
| 14 | + // Write the header |
| 15 | + try writer.writeAll( |
| 16 | + \\--- |
| 17 | + \\title: Reference |
| 18 | + \\description: Reference of all Ghostty action subcommands. |
| 19 | + \\editOnGithubLink: https://github.com/ghostty-org/ghostty/tree/main/src/cli |
| 20 | + \\--- |
| 21 | + \\Ghostty includes a number of utility actions that can be accessed as subcommands. |
| 22 | + \\Actions provide utilities to work with config, list keybinds, list fonts, demo themes, |
| 23 | + \\and debug. |
| 24 | + \\ |
| 25 | + ); |
| 26 | + |
| 27 | + inline for (@typeInfo(Action).Enum.fields) |field| { |
| 28 | + const action = std.meta.stringToEnum(Action, field.name).?; |
| 29 | + |
| 30 | + switch (action) { |
| 31 | + .help, .version => try writer.writeAll("## " ++ field.name ++ "\n"), |
| 32 | + else => try writer.writeAll("## " ++ field.name ++ "\n"), |
| 33 | + } |
| 34 | + |
| 35 | + if (@hasDecl(help_strings.Action, field.name)) { |
| 36 | + var iter = std.mem.splitScalar(u8, @field(help_strings.Action, field.name), '\n'); |
| 37 | + var first = true; |
| 38 | + while (iter.next()) |s| { |
| 39 | + try writer.writeAll(s); |
| 40 | + try writer.writeAll("\n"); |
| 41 | + first = false; |
| 42 | + } |
| 43 | + try writer.writeAll("\n```\n"); |
| 44 | + switch (action) { |
| 45 | + .help, .version => try writer.writeAll("ghostty --" ++ field.name ++ "\n"), |
| 46 | + else => try writer.writeAll("ghostty +" ++ field.name ++ "\n"), |
| 47 | + } |
| 48 | + try writer.writeAll("```\n\n"); |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments