Skip to content

Commit

Permalink
Actions: Add partial implementation of list action cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
briancain committed Feb 21, 2024
1 parent c201997 commit eb893e1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
2 changes: 0 additions & 2 deletions internal/commands/waypoint/actionconfig/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ type DeleteOpts struct {
opts.WaypointOpts

Name string
// We intentionally don't support ID for delete yet.
Id string
}

func NewCmdDelete(ctx *cmd.Context) *cmd.Command {
Expand Down
44 changes: 41 additions & 3 deletions internal/commands/waypoint/actionconfig/list.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,56 @@
package actionconfig

import "github.com/hashicorp/hcp/internal/pkg/cmd"
import (
"fmt"

"github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client/waypoint_service"
"github.com/hashicorp/hcp/internal/commands/waypoint/opts"
"github.com/hashicorp/hcp/internal/pkg/cmd"
)

type ListOpts struct {
opts.WaypointOpts
}

func NewCmdList(ctx *cmd.Context) *cmd.Command {
opts := &ListOpts{
WaypointOpts: opts.New(ctx),
}

cmd := &cmd.Command{
Name: "list",
ShortHelp: "List all known action configurations.",
LongHelp: "List all known action configuration.",
RunF: listActionConfig,
RunF: func(c *cmd.Command, args []string) error {
return listActionConfig(c, args, opts)
},
PersistentPreRun: func(c *cmd.Command, args []string) error {
return cmd.RequireOrgAndProject(ctx)
},
}

return cmd
}

func listActionConfig(c *cmd.Command, args []string) error {
func listActionConfig(c *cmd.Command, args []string, opts *ListOpts) error {
ns, err := opts.Namespace()
if err != nil {
return err
}

resp, err := opts.WS.WaypointServiceListActionConfigs(&waypoint_service.WaypointServiceListActionConfigsParams{
NamespaceID: ns.ID,
Context: opts.Ctx,
}, nil)
if err != nil {
fmt.Fprintf(opts.IO.Err(), "Error listing action configs: %s", err)
return err
}

respPayload := resp.GetPayload()
if len(respPayload.ActionConfigs) > 0 {
// Print them
}

return nil
}
12 changes: 5 additions & 7 deletions internal/commands/waypoint/actionconfig/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ type ShowOpts struct {
opts.WaypointOpts

Name string
// We intentionally don't support ID for delete yet.
Id string
}

func NewCmdShow(ctx *cmd.Context) *cmd.Command {
Expand Down Expand Up @@ -55,7 +53,7 @@ func showActionConfig(c *cmd.Command, args []string, opts *ShowOpts) error {

// Make action name a string pointer
actionName := &opts.Name
resp, err := opts.WS.WaypointServiceGetActionConfig(&waypoint_service.WaypointServiceGetActionConfigParams{
_, err = opts.WS.WaypointServiceGetActionConfig(&waypoint_service.WaypointServiceGetActionConfigParams{
NamespaceID: ns.ID,
Context: opts.Ctx,
ActionName: actionName,
Expand All @@ -65,10 +63,10 @@ func showActionConfig(c *cmd.Command, args []string, opts *ShowOpts) error {
return err
}

respPayload := resp.GetPayload()
actionCfg := respPayload.ActionConfig
latestRun := respPayload.LatestRun
totalRuns := respPayload.TotalRuns
// respPayload := resp.GetPayload()
// actionCfg := respPayload.ActionConfig
// latestRun := respPayload.LatestRun
// totalRuns := respPayload.TotalRuns

// TODO(briancain): add a displayer.go

Expand Down

0 comments on commit eb893e1

Please sign in to comment.