-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add ctrlc api get commands (#5) #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package deployments | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/ctrlplanedev/cli/internal/api" | ||
| "github.com/ctrlplanedev/cli/internal/cliutil" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| func NewDeploymentsCmd() *cobra.Command { | ||
| var limit int | ||
| var offset int | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "deployments", | ||
| Short: "Get deployments", | ||
| Long: `Commands for getting deployments.`, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| apiURL := viper.GetString("url") | ||
| apiKey := viper.GetString("api-key") | ||
| workspace := viper.GetString("workspace") | ||
|
|
||
| client, err := api.NewAPIKeyClientWithResponses(apiURL, apiKey) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create API client: %w", err) | ||
| } | ||
|
|
||
| workspaceID := client.GetWorkspaceID(cmd.Context(), workspace) | ||
|
|
||
| if workspaceID.String() == "00000000-0000-0000-0000-000000000000" { | ||
| return fmt.Errorf("invalid workspace: %s", workspace) | ||
| } | ||
|
|
||
| params := &api.ListDeploymentsParams{} | ||
| if limit > 0 { | ||
| params.Limit = &limit | ||
| } | ||
| if offset > 0 { | ||
| params.Offset = &offset | ||
| } | ||
|
|
||
| resp, err := client.ListDeployments(cmd.Context(), workspaceID.String(), params) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get deployments: %w", err) | ||
| } | ||
|
|
||
| return cliutil.HandleResponseOutput(cmd, resp) | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().IntVarP(&limit, "limit", "l", 50, "Limit the number of results") | ||
| cmd.Flags().IntVarP(&offset, "offset", "o", 0, "Offset the results") | ||
|
|
||
| cmd.MarkFlagRequired("workspace") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Same issue as in other commands—the 🤖 Prompt for AI Agents |
||
|
|
||
| return cmd | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package environments | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/ctrlplanedev/cli/internal/api" | ||
| "github.com/ctrlplanedev/cli/internal/cliutil" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| func NewEnvironmentsCmd() *cobra.Command { | ||
| var limit int | ||
| var offset int | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "environments", | ||
| Short: "Get environments", | ||
| Long: `Commands for getting environments.`, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| apiURL := viper.GetString("url") | ||
| apiKey := viper.GetString("api-key") | ||
| workspace := viper.GetString("workspace") | ||
|
|
||
| client, err := api.NewAPIKeyClientWithResponses(apiURL, apiKey) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create API client: %w", err) | ||
| } | ||
|
|
||
| workspaceID := client.GetWorkspaceID(cmd.Context(), workspace) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing error handling for Same issue as in the systems command — no validation of the workspace resolution result before using it. 🤖 Prompt for AI Agents |
||
|
|
||
| if workspaceID.String() == "00000000-0000-0000-0000-000000000000" { | ||
| return fmt.Errorf("invalid workspace: %s", workspace) | ||
| } | ||
|
|
||
| params := &api.ListEnvironmentsParams{} | ||
| if limit > 0 { | ||
| params.Limit = &limit | ||
| } | ||
| if offset > 0 { | ||
| params.Offset = &offset | ||
| } | ||
|
|
||
| resp, err := client.ListEnvironments(cmd.Context(), workspaceID.String(), params) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get environments: %w", err) | ||
| } | ||
|
|
||
| return cliutil.HandleResponseOutput(cmd, resp) | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().IntVarP(&limit, "limit", "l", 50, "Limit the number of results") | ||
| cmd.Flags().IntVarP(&offset, "offset", "o", 0, "Offset the results") | ||
|
|
||
| cmd.MarkFlagRequired("workspace") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Same issue as in systems.go—the 🤖 Prompt for AI Agents |
||
|
|
||
| return cmd | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package systems | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/ctrlplanedev/cli/internal/api" | ||
| "github.com/ctrlplanedev/cli/internal/cliutil" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| func NewSystemsCmd() *cobra.Command { | ||
| var limit int | ||
| var offset int | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "systems", | ||
| Short: "Get systems", | ||
| Long: `Commands for getting systems.`, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| apiURL := viper.GetString("url") | ||
| apiKey := viper.GetString("api-key") | ||
| workspace := viper.GetString("workspace") | ||
|
|
||
| client, err := api.NewAPIKeyClientWithResponses(apiURL, apiKey) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create API client: %w", err) | ||
| } | ||
|
|
||
| workspaceID := client.GetWorkspaceID(cmd.Context(), workspace) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if workspaceID.String() == "00000000-0000-0000-0000-000000000000" { | ||
| return fmt.Errorf("invalid workspace: %s", workspace) | ||
| } | ||
|
|
||
| params := &api.ListSystemsParams{} | ||
| if limit > 0 { | ||
| params.Limit = &limit | ||
| } | ||
| if offset > 0 { | ||
| params.Offset = &offset | ||
| } | ||
|
|
||
| resp, err := client.ListSystems(cmd.Context(), workspaceID.String(), params) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get systems: %w", err) | ||
| } | ||
|
|
||
| return cliutil.HandleResponseOutput(cmd, resp) | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().IntVarP(&limit, "limit", "l", 50, "Limit the number of results") | ||
| cmd.Flags().IntVarP(&offset, "offset", "o", 0, "Offset the results") | ||
|
|
||
| cmd.MarkFlagRequired("workspace") | ||
|
|
||
| return cmd | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.