From af6175cc56555b5c857016d76e5d2e6ab6d09d21 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Wed, 20 May 2026 14:20:58 +0200 Subject: [PATCH] rewrite help in a more compact way Inspired by go help output --- src/Config.zig | 26 ++-------------------- src/help.zon | 60 +++++++++++++++++++++++--------------------------- 2 files changed, 30 insertions(+), 56 deletions(-) diff --git a/src/Config.zig b/src/Config.zig index e54f175c..d74580a1 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -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 => { diff --git a/src/help.zon b/src/help.zon index 3ef55e62..25885708 100644 --- a/src/help.zon +++ b/src/help.zon @@ -1,18 +1,23 @@ .{ // MAX_HELP_LEN| .general = - \\Command can be either "fetch", "serve", "mcp" or "help". - \\Use '{0s} help ' for details. + \\usage: {0s} [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 " 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 of the CDP server. \\ Defaults to "127.0.0.1". \\ @@ -35,15 +40,12 @@ \\--cookie Path to a JSON file to load cookies from (read-only). \\ Defaults to no cookie loading. , - .fetch_cmd = - \\fetch command + .fetch = + \\usage: {0s} fetch [OPTIONS] [COMMON_OPTIONS] + \\ \\Fetches the specified URL. \\ - \\Usage: - \\ {0s} fetch [OPTIONS] [COMMON_OPTIONS] - , - .fetch_options = - \\Options: + \\options: \\--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 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.