Skip to content

Commit b5968a7

Browse files
committed
cmd: fix help text and examples
1 parent adff8f3 commit b5968a7

11 files changed

Lines changed: 48 additions & 10 deletions

File tree

cmd/heygen/builder.go

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

162162
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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ Environment Variables:
2626
HEYGEN_API_KEY API key for authentication (overrides stored credentials)
2727
HEYGEN_OUTPUT Output format: json, human (default: json)
2828
29-
Use "heygen config list" to see all configuration settings and their sources.`,
29+
Use "heygen config list" to see all configuration settings and their sources.
30+
31+
Exit Codes:
32+
0 Success
33+
1 General error (API error, network failure)
34+
2 Usage error (invalid flags, missing arguments)
35+
3 Authentication error (missing or invalid API key)`,
3036
Version: version,
3137
SilenceUsage: true, // we handle usage errors ourselves
3238
SilenceErrors: true, // we handle error output ourselves
@@ -39,6 +45,7 @@ Use "heygen config list" to see all configuration settings and their sources.`,
3945
root.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
4046
return clierrors.NewUsage(err.Error())
4147
})
48+
root.CompletionOptions.HiddenDefaultCmd = true
4249
root.PersistentFlags().Bool("human", false, "Display output as a formatted table instead of JSON")
4350

4451
root.AddCommand(newAuthCmd(ctx))
@@ -70,6 +77,7 @@ func newRootCmdWithSpecs(version string, formatter output.Formatter, groups map[
7077
root.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
7178
return clierrors.NewUsage(err.Error())
7279
})
80+
root.CompletionOptions.HiddenDefaultCmd = true
7381
root.PersistentFlags().Bool("human", false, "Display output as a formatted table instead of JSON")
7482

7583
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)