Skip to content

Commit 1a2b88e

Browse files
somanshreddyclaude
andauthored
cli: share hidden-command list via command.Spec.IsHidden so docs honor it (#213)
cli: move hidden-command list to command package as shared source of truth The hidden-command decision (pre-launch endpoints omitted from --help) lived in cmd/heygen (package main), so it was unreachable to anything outside the CLI binary. The EF docs generator, which imports gen and iterates raw specs, could not honor it and would publish pre-launch commands (e.g. `asset search`) to the public docs. Move the list + predicate to internal/command as Spec.IsHidden() so both the runtime builder (hides from --help) and the docs generator (omits from public docs) share one source of truth. Behavior in the CLI is unchanged. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 257819c commit 1a2b88e

4 files changed

Lines changed: 32 additions & 26 deletions

File tree

cmd/heygen/builder.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,6 @@ import (
2121
"golang.org/x/term"
2222
)
2323

24-
// hiddenCommands lists generated commands that remain fully functional but are omitted from
25-
// `--help` listings (Cobra Hidden) — for endpoints that exist in the OpenAPI spec but aren't
26-
// announced yet (still under development). The spec is the source of truth for what exists; this
27-
// hard-coded list is the CLI-side decision of what's discoverable. A hidden command still runs if
28-
// invoked directly, and its own `--help` works. Keyed by "METHOD /path" so it survives command
29-
// renames (e.g. an x-cli-action verb change).
30-
// To surface a command in --help, remove its entry here. This list is transitional, for endpoints
31-
// under development pre-launch; for a permanent hidden-from-help posture, plumb an `x-cli-hidden`
32-
// extension from the OpenAPI spec instead of hard-coding it here, so the spec stays the source of
33-
// truth.
34-
var hiddenCommands = map[string]bool{
35-
"GET /v3/assets/search": true, // asset search — pre-launch, not yet announced
36-
}
37-
38-
// isHiddenCommand reports whether the command for this spec should be omitted from help listings.
39-
func isHiddenCommand(spec *command.Spec) bool {
40-
return hiddenCommands[strings.ToUpper(spec.Method)+" "+spec.Endpoint]
41-
}
42-
4324
// buildCobraCommand creates a Cobra command from a command.Spec.
4425
// It registers typed flags, sets up positional arg validation, and wires
4526
// RunE to build an Invocation and execute it through the HTTP client.
@@ -56,7 +37,7 @@ func buildCobraCommand(spec *command.Spec, ctx *cmdContext) *cobra.Command {
5637
Short: spec.Summary,
5738
Long: description,
5839
Example: strings.Join(spec.Examples, "\n"),
59-
Hidden: isHiddenCommand(spec),
40+
Hidden: spec.IsHidden(),
6041
Args: func(cmd *cobra.Command, args []string) error {
6142
if isSchemaRequest(cmd) {
6243
return nil

cmd/heygen/help_flatten.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,16 @@ func isLeafCommand(cmd *cobra.Command) bool {
178178
}
179179

180180
// hideEmptyGroups hides any group command left with no visible children — e.g. an intermediate
181-
// group whose only leaf is in hiddenCommands. Without this, such a group reads as a leaf to the
181+
// group whose only leaf is hidden (see command.Spec.IsHidden). Without this, such a group reads as a leaf to the
182182
// flattened help and renders as a phantom entry. Runs bottom-up so a group whose children all
183183
// become hidden is itself hidden. The underlying command stays reachable and runnable; only its
184184
// help listing is suppressed.
185185
func hideEmptyGroups(cmd *cobra.Command) {
186186
for _, child := range cmd.Commands() {
187187
hideEmptyGroups(child)
188188
}
189-
// A command with subcommands but no visible ones is an empty group (e.g. its only leaf is in
190-
// hiddenCommands). Hide it. Leaves have no subcommands, so they're unaffected; intermediate
189+
// A command with subcommands but no visible ones is an empty group (e.g. its only leaf is
190+
// hidden). Hide it. Leaves have no subcommands, so they're unaffected; intermediate
191191
// groups carry a help-showing RunE, so we must not gate on Runnable().
192192
if cmd.HasSubCommands() && len(visibleChildren(cmd)) == 0 {
193193
cmd.Hidden = true

cmd/heygen/hidden_commands_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99

1010
func TestIsHiddenCommand(t *testing.T) {
1111
hidden := &command.Spec{Group: "asset", Name: "search", Method: "GET", Endpoint: "/v3/assets/search"}
12-
if !isHiddenCommand(hidden) {
12+
if !hidden.IsHidden() {
1313
t.Error("GET /v3/assets/search should be hidden")
1414
}
1515
// Method match is case-insensitive (specs may carry a lowercased method).
1616
lower := &command.Spec{Group: "asset", Name: "search", Method: "get", Endpoint: "/v3/assets/search"}
17-
if !isHiddenCommand(lower) {
17+
if !lower.IsHidden() {
1818
t.Error("method match should be case-insensitive")
1919
}
2020
visible := &command.Spec{Group: "video", Name: "list", Method: "GET", Endpoint: "/v3/videos"}
21-
if isHiddenCommand(visible) {
21+
if visible.IsHidden() {
2222
t.Error("GET /v3/videos should not be hidden")
2323
}
2424
}

internal/command/hidden.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package command
2+
3+
import "strings"
4+
5+
// hiddenEndpoints lists commands that remain fully functional but are omitted from `--help`
6+
// listings (Cobra Hidden) and from generated docs — for endpoints that exist in the OpenAPI spec
7+
// but aren't announced yet (still under development). The spec is the source of truth for what
8+
// exists; this hand-maintained list is the CLI-side decision of what's discoverable. A hidden
9+
// command still runs if invoked directly, and its own `--help` works. Keyed by "METHOD /path" so
10+
// it survives command renames (e.g. an x-cli-action verb change).
11+
//
12+
// This list lives here (not in the builder) so every consumer of a Spec shares one source of
13+
// truth: the runtime builder hides it from `--help`, and the docs generator omits it from public
14+
// docs. To surface a command, remove its entry here. This list is transitional, for endpoints
15+
// under development pre-launch; for a permanent hidden posture, plumb an `x-cli-hidden` extension
16+
// from the OpenAPI spec so the spec stays the source of truth.
17+
var hiddenEndpoints = map[string]bool{
18+
"GET /v3/assets/search": true, // asset search — pre-launch, not yet announced
19+
}
20+
21+
// IsHidden reports whether the command for this spec should be omitted from help listings and
22+
// generated docs.
23+
func (s Spec) IsHidden() bool {
24+
return hiddenEndpoints[strings.ToUpper(s.Method)+" "+s.Endpoint]
25+
}

0 commit comments

Comments
 (0)