Skip to content

Commit 95a2a10

Browse files
authored
cmd: fix help text and examples (#40)
## Description Fixes help text issues identified in internal testing. No code logic changes — text updates, codegen example fixes, and help improvements. **Examples fixed:** - `video create`: replaced non-existent `--avatar-id --script --voice-id` with realistic `--data` JSON - `video-agent create`: removed non-existent `--style-id`, added `--data` alternative alongside `--prompt` - `video-translate create`: added `--output-languages` flag example (existing flag, was missing from examples) - `video-agent sessions resources`: fixed verb from `list` to `get` (singleton endpoint) **Help text improvements:** - `--data` flag now documents merge behavior: "When used with individual flags, flags override matching fields in the JSON." - Root `--help` shows exit codes (0=success, 1=general, 2=usage, 3=auth) - `completion` command hidden from top-level help via `CompletionOptions.HiddenDefaultCmd` **Group descriptions:** - `voice`: "Text-to-speech and voice management" → "Create speech audio and manage voices" - `webhook`: "Manage webhook endpoints and events" → "Create, list, and manage webhook endpoints and events" - Implemented via `descriptionOverrides` map in `codegen/grouper.go` Stacked on PR #39 (spinner). ## Testing 1 new test: `TestGeneratedRoot_Help_ShowsExitCodesAndHidesCompletion` — verifies exit codes in help output and completion command hidden. Generated files regenerated with `make generate`. Golden files unchanged (examples are not in golden test spec).
1 parent a5fcb97 commit 95a2a10

11 files changed

Lines changed: 41 additions & 9 deletions

File tree

cmd/heygen/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func buildCobraCommand(spec *command.Spec, ctx *cmdContext) *cobra.Command {
147147
// Add -d/--data for commands with JSON request bodies
148148
if spec.BodyEncoding == "json" {
149149
cmd.Flags().StringVarP(&rawData, "data", "d", "",
150-
"JSON request body (inline JSON, file path, or - for stdin)")
150+
"JSON request body (inline JSON, file path, or - for stdin). When used with individual flags, flags override matching fields in the JSON.")
151151
}
152152

153153
return cmd

cmd/heygen/generated_root_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,23 @@ func TestGeneratedRoot_IntermediateHelp(t *testing.T) {
130130
}
131131
}
132132

133+
func TestGeneratedRoot_Help_ShowsExitCodesAndHidesCompletion(t *testing.T) {
134+
srv := setupTestServer(t, map[string]testHandler{})
135+
defer srv.Close()
136+
137+
res := runCommand(t, srv.URL, "test-key", "--help")
138+
139+
if res.ExitCode != 0 {
140+
t.Errorf("ExitCode = %d, want 0\nstderr: %s", res.ExitCode, res.Stderr)
141+
}
142+
if !strings.Contains(res.Stdout, "Exit Codes:") || !strings.Contains(res.Stdout, "3 Authentication error") {
143+
t.Errorf("root help missing documented exit codes\nstdout: %s", res.Stdout)
144+
}
145+
if strings.Contains(res.Stdout, "completion") {
146+
t.Errorf("root help should hide completion command\nstdout: %s", res.Stdout)
147+
}
148+
}
149+
133150
func TestGeneratedRoot_VideoAgentHelp_FlattensNestedLeaves(t *testing.T) {
134151
srv := setupTestServer(t, map[string]testHandler{})
135152
defer srv.Close()

cmd/heygen/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Exit Codes:
4646
root.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
4747
return clierrors.NewUsage(err.Error())
4848
})
49+
root.CompletionOptions.HiddenDefaultCmd = true
4950
root.PersistentFlags().Bool("human", false, "Display output as a formatted table instead of JSON")
5051

5152
root.AddCommand(newAuthCmd(ctx))
@@ -77,6 +78,7 @@ func newRootCmdWithSpecs(version string, formatter output.Formatter, groups map[
7778
root.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
7879
return clierrors.NewUsage(err.Error())
7980
})
81+
root.CompletionOptions.HiddenDefaultCmd = true
8082
root.PersistentFlags().Bool("human", false, "Display output as a formatted table instead of JSON")
8183

8284
root.AddCommand(newAuthCmd(ctx))

codegen/examples/video-agent.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"POST /v3/video-agents":
2-
- "heygen video-agent create --prompt 'Make a product demo' --style-id modern"
2+
- "heygen video-agent create --prompt 'Make a product demo'"
3+
- "heygen video-agent create -d '{\"prompt\":\"Make a product demo\"}'"
34
"GET /v3/video-agents/styles":
45
- "heygen video-agent styles list"
56
"POST /v3/video-agents/sessions":
@@ -9,6 +10,6 @@
910
"POST /v3/video-agents/sessions/{session_id}/messages":
1011
- "heygen video-agent sessions messages create <session-id> --message 'Add intro'"
1112
"GET /v3/video-agents/sessions/{session_id}/resources":
12-
- "heygen video-agent sessions resources list <session-id>"
13+
- "heygen video-agent sessions resources get <session-id>"
1314
"POST /v3/video-agents/sessions/{session_id}/stop":
1415
- "heygen video-agent sessions stop <session-id>"

codegen/examples/video-translate.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- "heygen video-translate get <video-translation-id>"
55
"POST /v3/video-translations":
66
- "cat request.json | heygen video-translate create -d -"
7+
- "heygen video-translate create --output-languages es --mode precision"
78
"PATCH /v3/video-translations/{video_translation_id}":
89
- "heygen video-translate update <video-translation-id> --title 'New title'"
910
"DELETE /v3/video-translations/{video_translation_id}":

codegen/examples/video.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- "heygen video list --limit 10"
33
- "heygen video list --folder-id abc123"
44
"POST /v3/videos":
5-
- "heygen video create --avatar-id josh_lite --script 'Hello world' --voice-id en_male"
5+
- "heygen video create -d '{\"video_inputs\":[{\"character\":{\"type\":\"avatar\",\"avatar_id\":\"josh_lite\"},\"voice\":{\"type\":\"text\",\"voice_id\":\"en_male\",\"input_text\":\"Hello world\"}}]}'"
66
"GET /v3/videos/{video_id}":
77
- "heygen video get <video-id>"
88
"DELETE /v3/videos/{video_id}":

codegen/grouper.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,22 @@ import (
5858
// Used by the builder for group command help text.
5959
type GroupDescriptions map[string]string
6060

61+
var descriptionOverrides = GroupDescriptions{
62+
"voice": "Create speech audio and manage voices",
63+
"webhook": "Create, list, and manage webhook endpoints and events",
64+
}
65+
6166
func GroupEndpoints(doc *openapi3.T, examples Examples) (command.Groups, GroupDescriptions, error) {
6267
groups := make(command.Groups)
6368
descriptions := make(GroupDescriptions)
6469

6570
// Collect tag descriptions from the spec's top-level tags array
6671
for _, tag := range doc.Tags {
6772
groupName := deriveGroupName(tag.Name)
73+
if override, ok := descriptionOverrides[groupName]; ok {
74+
descriptions[groupName] = override
75+
continue
76+
}
6877
if tag.Description != "" {
6978
descriptions[groupName] = tag.Description
7079
}

gen/registry.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/video-agent.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/video-translate.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)