Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cmd/heygen/gen_register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"github.com/heygen-com/heygen-cli/gen"
"github.com/spf13/cobra"
)

// registerGenCommands adds all generated command groups to the root command.
// Each group becomes a Cobra subcommand (e.g., "video", "avatar"), and each
// spec within the group becomes a leaf command (e.g., "video list", "avatar get").
func registerGenCommands(root *cobra.Command, ctx *cmdContext) {
for groupName, specs := range gen.Groups {
groupCmd := &cobra.Command{
Use: groupName,
Short: "Manage " + groupName,
}
for _, spec := range specs {
groupCmd.AddCommand(buildGenCommand(spec, ctx))
}
root.AddCommand(groupCmd)
}
}
4 changes: 2 additions & 2 deletions cmd/heygen/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func newRootCmd(version string, formatter output.Formatter) *cobra.Command {
return clierrors.NewUsage(err.Error())
})

// Register subcommands
root.AddCommand(newVideoCmd(ctx))
// Register generated commands from gen/ package
registerGenCommands(root, ctx)

return root
}
Expand Down
12 changes: 0 additions & 12 deletions cmd/heygen/video.go

This file was deleted.

57 changes: 0 additions & 57 deletions cmd/heygen/video_list.go

This file was deleted.

26 changes: 10 additions & 16 deletions cmd/heygen/video_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,32 +124,26 @@ func TestVideoList_Flags(t *testing.T) {
if got := q.Get("folder_id"); got != "folder_abc" {
t.Errorf("folder_id = %q, want %q", got, "folder_abc")
}
if got := q.Get("token"); got != "cursor_xyz" {
t.Errorf("token = %q, want %q", got, "cursor_xyz")
if got := q.Get("title"); got != "demo" {
t.Errorf("title = %q, want %q", got, "demo")
}
},
},
})
defer srv.Close()

res := runCommand(t, srv.URL, "test-key",
"video", "list", "--limit", "25", "--folder-id", "folder_abc", "--token", "cursor_xyz")
"video", "list", "--limit", "25", "--folder-id", "folder_abc", "--title", "demo")

if res.ExitCode != 0 {
t.Errorf("ExitCode = %d, want 0\nstderr: %s", res.ExitCode, res.Stderr)
}
}

func TestVideoList_LimitOutOfRange(t *testing.T) {
// The OpenAPI spec doesn't define min/max for limit, so validation
// is server-side. The API returns 400 (exit 1), not a client-side
// usage error (exit 2).
srv := setupTestServer(t, map[string]testHandler{
"GET /v3/videos": {
StatusCode: 400,
Body: `{"error":{"code":"invalid_parameter","message":"limit must be between 1 and 100"}}`,
},
})
// The codegen reads min/max from the OpenAPI spec. Client-side
// validation catches out-of-range values before the API call.
srv := setupTestServer(t, map[string]testHandler{})
defer srv.Close()

tests := []struct {
Expand All @@ -164,16 +158,16 @@ func TestVideoList_LimitOutOfRange(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
res := runCommand(t, srv.URL, "test-key", "video", "list", "--limit", tt.limit)

if res.ExitCode != clierrors.ExitGeneral {
t.Errorf("ExitCode = %d, want %d\nstderr: %s", res.ExitCode, clierrors.ExitGeneral, res.Stderr)
if res.ExitCode != clierrors.ExitUsage {
t.Errorf("ExitCode = %d, want %d\nstderr: %s", res.ExitCode, clierrors.ExitUsage, res.Stderr)
}

var envelope map[string]map[string]any
if err := json.Unmarshal([]byte(res.Stderr), &envelope); err != nil {
t.Fatalf("stderr is not valid JSON: %v\nstderr: %s", err, res.Stderr)
}
if envelope["error"]["code"] != "invalid_parameter" {
t.Errorf("error.code = %v, want %q", envelope["error"]["code"], "invalid_parameter")
if envelope["error"]["code"] != "usage_error" {
t.Errorf("error.code = %v, want %q", envelope["error"]["code"], "usage_error")
}
})
}
Expand Down
21 changes: 21 additions & 0 deletions gen/asset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

186 changes: 186 additions & 0 deletions gen/avatar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading