Skip to content

Commit

Permalink
Example usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar committed Feb 26, 2024
1 parent 6083ee6 commit 1b2aebd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 61 deletions.
2 changes: 1 addition & 1 deletion internal/commands/projects/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func createRun(opts *CreateOpts) error {
}

// Display the created project
d := newDisplayer(format.Pretty, true, resp.Payload.Project)
d := format.NewDisplayer(resp.Payload.Project, format.Pretty, projectFields)
if err := opts.Output.Display(d); err != nil {
return err
}
Expand Down
57 changes: 0 additions & 57 deletions internal/commands/projects/displayer.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/commands/projects/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ func listRun(opts *ListOpts) error {
req.PaginationNextPageToken = &next
}

d := newDisplayer(format.Table, false, projects...)
d := format.NewDisplayer(projects, format.Table, projectFields)
return opts.Output.Display(d)
}
11 changes: 11 additions & 0 deletions internal/commands/projects/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@ package projects
import (
"github.com/hashicorp/hcp/internal/commands/projects/iam"
"github.com/hashicorp/hcp/internal/pkg/cmd"
"github.com/hashicorp/hcp/internal/pkg/format"
"github.com/hashicorp/hcp/internal/pkg/heredoc"
)

var (
// projectFields is the set of fields to display for a project.
projectFields = []format.Field{
format.NewField("Name", "{{ .Name }}"),
format.NewField("ID", "{{ .ID }}"),
format.NewField("Description", "{{ .Description }}"),
format.NewField("Created At", "{{ .CreatedAt }}"),
}
)

func NewCmdProjects(ctx *cmd.Context) *cmd.Command {
cmd := &cmd.Command{
Name: "projects",
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/projects/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewCmdRead(ctx *cmd.Context, runF func(*ReadOpts) error) *cmd.Command {
LongHelp: "Show metadata for the project.",
Examples: []cmd.Example{
{
Preamble: "Read a project:",
Preamble: "Read a project.",
Command: "$ hcp projects read --project=cd3d34d5-ceeb-493d-b004-9297365a01af",
},
},
Expand Down Expand Up @@ -61,6 +61,6 @@ func readRun(opts *ReadOpts) error {
return fmt.Errorf("failed to read project: %w", err)
}

d := newDisplayer(format.Pretty, true, resp.Payload.Project)
d := format.NewDisplayer(resp.Payload.Project, format.Pretty, projectFields)
return opts.Output.Display(d)
}

0 comments on commit 1b2aebd

Please sign in to comment.