Skip to content

Commit 098a46f

Browse files
anundmitchellh
authored andcommitted
docs: generate mdx file for cli actions
1 parent 168dd31 commit 098a46f

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

src/build/Config.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ pub const ExeEntrypoint = enum {
486486
mdgen_ghostty_5,
487487
webgen_config,
488488
webgen_actions,
489+
webgen_commands,
489490
bench_parser,
490491
bench_stream,
491492
bench_codepoint_width,

src/build/GhosttyWebdata.zig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,35 @@ pub fn init(
7373
).step);
7474
}
7575

76+
{
77+
const webgen_commands = b.addExecutable(.{
78+
.name = "webgen_commands",
79+
.root_source_file = b.path("src/main.zig"),
80+
.target = b.host,
81+
});
82+
deps.help_strings.addImport(webgen_commands);
83+
84+
{
85+
const buildconfig = config: {
86+
var copy = deps.config.*;
87+
copy.exe_entrypoint = .webgen_commands;
88+
break :config copy;
89+
};
90+
91+
const options = b.addOptions();
92+
try buildconfig.addOptions(options);
93+
webgen_commands.root_module.addOptions("build_options", options);
94+
}
95+
96+
const webgen_commands_step = b.addRunArtifact(webgen_commands);
97+
const webgen_commands_out = webgen_commands_step.captureStdOut();
98+
99+
try steps.append(&b.addInstallFile(
100+
webgen_commands_out,
101+
"share/ghostty/webdata/commands.mdx",
102+
).step);
103+
}
104+
76105
return .{ .steps = steps.items };
77106
}
78107

src/build/webgen/main_commands.zig

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

src/cli/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Subcommand Actions
2+
3+
This is the cli specific code. It contains cli actions and tui definitions and
4+
argument parsing.
5+
6+
This README is meant as developer documentation and not as user documentation.
7+
For user documentation, see the main README or [ghostty.org](https://ghostty.org/docs).
8+
9+
## Updating documentation
10+
11+
Each cli action is defined in it's own file. Documentation for each action is defined
12+
in the doc comment associated with the `run` function. For example the `run` function
13+
in `list_keybinds.zig` contains the help text for `ghostty +list-keybinds`.

src/main.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const entrypoint = switch (build_config.exe_entrypoint) {
99
.mdgen_ghostty_5 => @import("build/mdgen/main_ghostty_5.zig"),
1010
.webgen_config => @import("build/webgen/main_config.zig"),
1111
.webgen_actions => @import("build/webgen/main_actions.zig"),
12+
.webgen_commands => @import("build/webgen/main_commands.zig"),
1213
.bench_parser => @import("bench/parser.zig"),
1314
.bench_stream => @import("bench/stream.zig"),
1415
.bench_codepoint_width => @import("bench/codepoint-width.zig"),

0 commit comments

Comments
 (0)