rewrite help in a more compact way

Inspired by go help output
This commit is contained in:
Pierre Tachoire
2026-05-20 14:20:58 +02:00
parent dffa961f45
commit af6175cc56
2 changed files with 30 additions and 56 deletions

View File

@@ -552,25 +552,9 @@ pub fn printUsageAndExit(self: *const Config, help_for: RunMode, success: bool)
// Requested help for everything.
.help => {
const template = comptimePrint(
\\
\\{s}
\\
\\
\\{s}
\\
\\
\\{s}
\\
\\
\\{s}
\\
\\
\\{s}
\\
\\
\\{s}
\\
, .{ Help.general, Help.fetch_cmd, Help.serve_cmd, Help.mcp_cmd, Help.version, Help.help });
, .{Help.general});
std.debug.print(template, .{exec_name});
},
inline .fetch, .serve, .mcp => |tag| {
@@ -579,13 +563,7 @@ pub fn printUsageAndExit(self: *const Config, help_for: RunMode, success: bool)
\\
\\{s}
\\
\\{s}
\\
, .{
@field(Help, @tagName(tag) ++ "_cmd"),
@field(Help, @tagName(tag) ++ "_options"),
Help.common_options,
});
, .{ @field(Help, @tagName(tag)), Help.common_options });
std.debug.print(template, .{ exec_name, info_or_warn, pretty_or_logfmt });
},
.version => {

View File

@@ -1,18 +1,23 @@
.{
// MAX_HELP_LEN|
.general =
\\Command can be either "fetch", "serve", "mcp" or "help".
\\Use '{0s} help <command>' for details.
\\usage: {0s} <command> [arguments]
\\
\\The commands are:
\\ serve starts a WebSocket CDP server
\\ fetch fetches the specified URL
\\ mcp starts an MCP (Model Context Protocol) server over stdio
\\ version displays the version of {0s}
\\ help displays this message
\\
\\Use "{0s} help <command>" for more information about a command.
,
.serve_cmd =
\\serve command
.serve =
\\usage: {0s} serve [OPTIONS] [COMMON_OPTIONS]
\\
\\Starts a WebSocket CDP server.
\\
\\Usage:
\\ {0s} serve [OPTIONS] [COMMON_OPTIONS]
,
.serve_options =
\\Options:
\\options:
\\--host <HOST> Host of the CDP server.
\\ Defaults to "127.0.0.1".
\\
@@ -35,15 +40,12 @@
\\--cookie <PATH> Path to a JSON file to load cookies from (read-only).
\\ Defaults to no cookie loading.
,
.fetch_cmd =
\\fetch command
.fetch =
\\usage: {0s} fetch <url> [OPTIONS] [COMMON_OPTIONS]
\\
\\Fetches the specified URL.
\\
\\Usage:
\\ {0s} fetch <url> [OPTIONS] [COMMON_OPTIONS]
,
.fetch_options =
\\Options:
\\options:
\\--dump <DUMP> Dumps the document to stdout.
\\ Defaults to no dump.
\\
@@ -115,15 +117,12 @@
\\ (write-only).
\\ Defaults to no cookie saving.
,
.mcp_cmd =
\\mcp command
.mcp =
\\usage: {0s} mcp [OPTIONS] [COMMON_OPTIONS]
\\
\\Starts an MCP (Model Context Protocol) server over stdio.
\\
\\Usage:
\\ {0s} mcp [OPTIONS] [COMMON_OPTIONS]
,
.mcp_options =
\\Options:
\\options:
\\--cookie <PATH> Path to a JSON file to load cookies from (read-only).
\\ Defaults to no cookie loading.
\\
@@ -132,21 +131,18 @@
\\ Defaults to no cookie saving.
,
.version =
\\version command
\\Displays the version of {0s}.
\\usage: {0s} version
\\
\\Usage:
\\ {0s} version
\\Displays the version of {0s}.
,
.help =
\\help command
\\Displays this message.
\\usage: {0s} help
\\
\\Displays help message for a command.
\\
\\Usage:
\\ {0s} help
,
.common_options =
\\Common Options:
\\common options:
\\--insecure-disable-tls-host-verification
\\ Disables host verification on all HTTP requests.
\\ Only set this if you understand and accept the risk.