-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actions: Add partial implementation of list action cmd
- Loading branch information
Showing
3 changed files
with
46 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters