Skip to content

Commit deb9033

Browse files
authored
Generate mdx for cli actions (#4499)
Duplicate existing reference docs generation to cover cli actions. Docs update pass to make the structure consistent. See ghostty-org/website#253 for website changes.
2 parents 78a2a81 + 098a46f commit deb9033

File tree

14 files changed

+138
-23
lines changed

14 files changed

+138
-23
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/cli/action.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ pub const Action = enum {
4545
// Validate passed config file
4646
@"validate-config",
4747

48-
// List, (eventually) view, and (eventually) send crash reports.
49-
@"crash-report",
50-
5148
// Show which font face Ghostty loads a codepoint from.
5249
@"show-face",
5350

51+
// List, (eventually) view, and (eventually) send crash reports.
52+
@"crash-report",
53+
5454
pub const Error = error{
5555
/// Multiple actions were detected. You can specify at most one
5656
/// action on the CLI otherwise the behavior desired is ambiguous.

src/cli/help.zig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ pub const Options = struct {
1515
}
1616
};
1717

18-
/// The `help` command shows general help about Ghostty. You can also specify
19-
/// `--help` or `-h` along with any action such as `+list-themes` to see help
20-
/// for a specific action.
18+
/// The `help` command shows general help about Ghostty. Recognized as either
19+
/// `-h, `--help`, or like other actions `+help`.
20+
///
21+
/// You can also specify `--help` or `-h` along with any action such as
22+
/// `+list-themes` to see help for a specific action.
2123
pub fn run(alloc: Allocator) !u8 {
2224
var opts: Options = .{};
2325
defer opts.deinit();

src/cli/list_actions.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ pub const Options = struct {
2424
/// actions for Ghostty. These are distinct from the CLI Actions which can
2525
/// be listed via `+help`
2626
///
27-
/// The `--docs` argument will print out the documentation for each action.
27+
/// Flags:
28+
///
29+
/// * `--docs`: will print out the documentation for each action.
2830
pub fn run(alloc: Allocator) !u8 {
2931
var opts: Options = .{};
3032
defer opts.deinit();

src/cli/list_fonts.zig

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,21 @@ pub const Options = struct {
4444
/// the sorting will be disabled and the results instead will be shown in the
4545
/// same priority order Ghostty would use to pick a font.
4646
///
47-
/// The `--family` argument can be used to filter results to a specific family.
48-
/// The family handling is identical to the `font-family` set of Ghostty
49-
/// configuration values, so this can be used to debug why your desired font may
50-
/// not be loading.
47+
/// Flags:
5148
///
52-
/// The `--bold` and `--italic` arguments can be used to filter results to
53-
/// specific styles. It is not guaranteed that only those styles are returned,
54-
/// it will just prioritize fonts that match those styles.
49+
/// * `--bold`: Filter results to specific bold styles. It is not guaranteed
50+
/// that only those styles are returned. They are only prioritized.
51+
///
52+
/// * `--italic`: Filter results to specific italic styles. It is not guaranteed
53+
/// that only those styles are returned. They are only prioritized.
54+
///
55+
/// * `--style`: Filter results based on the style string advertised by a font.
56+
/// It is not guaranteed that only those styles are returned. They are only
57+
/// prioritized.
58+
///
59+
/// * `--family`: Filter results to a specific font family. The family handling
60+
/// is identical to the `font-family` set of Ghostty configuration values, so
61+
/// this can be used to debug why your desired font may not be loading.
5562
pub fn run(alloc: Allocator) !u8 {
5663
var iter = try args.argsIterator(alloc);
5764
defer iter.deinit();

src/cli/list_keybinds.zig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ pub const Options = struct {
4242
/// changes to the keybinds it will print out the default ones configured for
4343
/// Ghostty
4444
///
45-
/// The `--default` argument will print out all the default keybinds configured
46-
/// for Ghostty
45+
/// Flags:
4746
///
48-
/// The `--plain` flag will disable formatting and make the output more
49-
/// friendly for Unix tooling. This is default when not printing to a tty.
47+
/// * `--default`: will print out all the default keybinds
48+
///
49+
/// * `--docs`: currently does nothing, intended to print out documentation
50+
/// about the action associated with the keybinds
51+
///
52+
/// * `--plain`: will disable formatting and make the output more
53+
/// friendly for Unix tooling. This is default when not printing to a tty.
5054
pub fn run(alloc: Allocator) !u8 {
5155
var opts: Options = .{};
5256
defer opts.deinit();

src/cli/list_themes.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const ThemeListElement = struct {
9191
/// Flags:
9292
///
9393
/// * `--path`: Show the full path to the theme.
94+
///
9495
/// * `--plain`: Force a plain listing of themes.
9596
pub fn run(gpa_alloc: std.mem.Allocator) !u8 {
9697
var opts: Options = .{};

0 commit comments

Comments
 (0)