Skip to content

Commit 4fd3bc6

Browse files
Merge pull request #73 from ctrlplanedev/get-deployment-name
chore: get deployment by name
2 parents 1dd6033 + 375c01f commit 4fd3bc6

3 files changed

Lines changed: 952 additions & 65 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package deployment
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/ctrlplanedev/cli/internal/api"
7+
"github.com/ctrlplanedev/cli/internal/cliutil"
8+
"github.com/spf13/cobra"
9+
"github.com/spf13/viper"
10+
)
11+
12+
func NewDeploymentCmd() *cobra.Command {
13+
var name string
14+
cmd := &cobra.Command{
15+
Use: "deployment",
16+
Short: "Get a deployment",
17+
Long: "Get a deployment by name",
18+
RunE: func(cmd *cobra.Command, args []string) error {
19+
apiURL := viper.GetString("url")
20+
apiKey := viper.GetString("api-key")
21+
workspace := viper.GetString("workspace")
22+
23+
client, err := api.NewAPIKeyClientWithResponses(apiURL, apiKey)
24+
if err != nil {
25+
return fmt.Errorf("failed to create API client: %w", err)
26+
}
27+
28+
workspaceID := client.GetWorkspaceID(cmd.Context(), workspace)
29+
resp, err := client.GetDeploymentByName(cmd.Context(), workspaceID.String(), name)
30+
if err != nil {
31+
return fmt.Errorf("failed to get deployment: %w", err)
32+
}
33+
34+
return cliutil.HandleResponseOutput(cmd, resp)
35+
},
36+
}
37+
38+
cmd.Flags().StringVarP(&name, "name", "n", "", "Deployment name")
39+
cmd.MarkFlagRequired("name")
40+
41+
cmd.MarkFlagRequired("workspace")
42+
43+
return cmd
44+
}

‎cmd/ctrlc/root/api/get/get.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package get
22

33
import (
4+
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/get/deployment"
45
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/get/release"
56
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/get/releasetargets"
67
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/get/resources"
@@ -20,6 +21,7 @@ func NewGetCmd() *cobra.Command {
2021
cmd.AddCommand(resources.NewResourcesCmd())
2122
cmd.AddCommand(release.NewReleaseCmd())
2223
cmd.AddCommand(releasetargets.NewReleaseTargetsCmd())
24+
cmd.AddCommand(deployment.NewDeploymentCmd())
2325

2426
return cmd
2527
}

0 commit comments

Comments
 (0)