From d67271a0fa282ca9338bfa53f72b98d151582a5a Mon Sep 17 00:00:00 2001 From: khooihongzhe Date: Wed, 18 Mar 2026 10:56:18 +0800 Subject: [PATCH 1/3] feat: surface `cg commands` in help output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The hidden `cg commands` endpoint outputs a machine-readable JSON catalog of all commands, flags, enums, and API mappings — useful for agents and tooling. Until now it was only discoverable via CLAUDE.md. Add a footer line to `cg --help` so users and agents can find it. --- cmd/root.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/root.go b/cmd/root.go index d3994b8..3669f7b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -32,6 +32,9 @@ func init() { func Execute() { rootCmd.SilenceUsage = true rootCmd.SilenceErrors = true + rootCmd.SetUsageTemplate(rootCmd.UsageTemplate() + + "\nUse \"cg commands\" for machine-readable command catalog (JSON)\n") + if err := rootCmd.Execute(); err != nil { // Emit structured JSON error to stderr when -o json, otherwise plain text. cmd, _, _ := rootCmd.Find(os.Args[1:]) From 9f0a6d9a5afdabbc40a0c2feb39bb72919d893af Mon Sep 17 00:00:00 2001 From: khooihongzhe Date: Sat, 21 Mar 2026 17:44:47 +0800 Subject: [PATCH 2/3] feat: add `cg commands` entry to welcome banner Surface the machine-readable catalog command in the interactive welcome box so agents and users discover it on first launch. --- internal/display/banner.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/display/banner.go b/internal/display/banner.go index 2cf839e..fcd60be 100644 --- a/internal/display/banner.go +++ b/internal/display/banner.go @@ -67,6 +67,7 @@ func PrintWelcomeBox() { printCmdRow(w, "cg top-gainers-losers", "# Top gainers (paid)") printCmdRow(w, "cg watch --ids bitcoin", "# Live prices (paid)") printCmdRow(w, "cg tui markets", "# Interactive TUI") + printCmdRow(w, "cg commands", "# Machine-readable catalog (JSON)") _, _ = fmt.Fprintln(w, blank) _, _ = fmt.Fprintln(w, sep) _, _ = fmt.Fprintln(w, blank) From a7fd93692c2c961979018b9927fb47b98a3f93be Mon Sep 17 00:00:00 2001 From: khooihongzhe Date: Sat, 21 Mar 2026 18:39:16 +0800 Subject: [PATCH 3/3] refactor: un-hide `commands` instead of manually advertising it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove Hidden: true from commandsCmd so it appears naturally in `cg --help` alongside every other command. This replaces the previous approach of keeping it hidden while manually adding hints to the usage template and welcome banner — simpler, more conventional, and zero additional code. --- cmd/commands.go | 7 +++---- cmd/root.go | 3 --- internal/display/banner.go | 1 - 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/cmd/commands.go b/cmd/commands.go index d87d69b..d2b11d2 100644 --- a/cmd/commands.go +++ b/cmd/commands.go @@ -148,10 +148,9 @@ type commandCatalog struct { } var commandsCmd = &cobra.Command{ - Use: "commands", - Short: "Output machine-readable command catalog (JSON)", - Hidden: true, - RunE: runCommands, + Use: "commands", + Short: "Output machine-readable command catalog (JSON)", + RunE: runCommands, } func init() { diff --git a/cmd/root.go b/cmd/root.go index 3669f7b..d3994b8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -32,9 +32,6 @@ func init() { func Execute() { rootCmd.SilenceUsage = true rootCmd.SilenceErrors = true - rootCmd.SetUsageTemplate(rootCmd.UsageTemplate() + - "\nUse \"cg commands\" for machine-readable command catalog (JSON)\n") - if err := rootCmd.Execute(); err != nil { // Emit structured JSON error to stderr when -o json, otherwise plain text. cmd, _, _ := rootCmd.Find(os.Args[1:]) diff --git a/internal/display/banner.go b/internal/display/banner.go index fcd60be..2cf839e 100644 --- a/internal/display/banner.go +++ b/internal/display/banner.go @@ -67,7 +67,6 @@ func PrintWelcomeBox() { printCmdRow(w, "cg top-gainers-losers", "# Top gainers (paid)") printCmdRow(w, "cg watch --ids bitcoin", "# Live prices (paid)") printCmdRow(w, "cg tui markets", "# Interactive TUI") - printCmdRow(w, "cg commands", "# Machine-readable catalog (JSON)") _, _ = fmt.Fprintln(w, blank) _, _ = fmt.Fprintln(w, sep) _, _ = fmt.Fprintln(w, blank)