Skip to content

Commit

Permalink
Fix displayer issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
teresamychu committed Feb 27, 2024
1 parent 7112a85 commit b9602c4
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions internal/commands/waypoint/tfcconfig/tfc_config_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client/waypoint_service"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models"
"github.com/hashicorp/hcp/internal/pkg/cmd"
"github.com/hashicorp/hcp/internal/pkg/format"
"github.com/hashicorp/hcp/internal/pkg/heredoc"
Expand Down Expand Up @@ -32,7 +33,7 @@ func NewCmdRead(ctx *cmd.Context, runF func(opts *TFCConfigReadOpts) error) *cmd
{
Preamble: `Retrieve the saved TFC Config from Waypoint for this HCP Project ID:`,
Command: heredoc.New(ctx.IO, heredoc.WithPreserveNewlines()).Must(`
$ hcp waypoint tfc-config get`),
$ hcp waypoint tfc-config read`),
},
},
RunF: func(c *cmd.Command, args []string) error {
Expand Down Expand Up @@ -63,27 +64,37 @@ func readRun(opts *TFCConfigReadOpts) error {
return fmt.Errorf("error retrieving TFC config: %w", err)

}
return opts.Output.Display(rolesDisplayer(roles))
d := newDisplayer(format.Pretty, resp.Payload.TfcConfig)
return opts.Output.Display(d)
}

type configDisplayer *models.HashicorpCloudWaypointTFCConfig
type configDisplayer struct {
config *models.HashicorpCloudWaypointTFCConfig
defaultFormat format.Format
}

func (d configDisplayer) DefaultFormat() format.Format { return format.Pretty }
func (d configDisplayer) Payload() any { return d }
func newDisplayer(defaultFormat format.Format, config *models.HashicorpCloudWaypointTFCConfig) *configDisplayer {
return &configDisplayer{
config: config,
defaultFormat: defaultFormat,
}
}

func (d configDisplayer) DefaultFormat() format.Format { return d.defaultFormat }
func (d configDisplayer) Payload() any { return d.config }

func (d configDisplayer) FieldTemplates() []format.Field {
return []format.Field{
{
Name: "Organization Name",
ValueFormat: "{{ . OrganizationName }}",
ValueFormat: "{{ .OrganizationName }}",
},
{
Name: "Token",
ValueFormat: "{{ . Token }}",
ValueFormat: "{{ .Token }}",
},
}
}
}

type TFCConfigReadOpts struct {
Ctx context.Context
Expand Down

0 comments on commit b9602c4

Please sign in to comment.