Skip to content

Commit

Permalink
Merge pull request #54 from hashicorp/waypoint-improvements
Browse files Browse the repository at this point in the history
Improve Waypoint CLI UX
  • Loading branch information
paladin-devops authored Apr 4, 2024
2 parents d5d52c1 + 698f700 commit aab8602
Show file tree
Hide file tree
Showing 20 changed files with 166 additions and 61 deletions.
16 changes: 12 additions & 4 deletions internal/commands/waypoint/add-ons/definitions/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,16 @@ $ hcp waypoint add-ons definitions create -n my-add-on-definition \
func addOnDefinitionCreate(opts *AddOnDefinitionOpts) error {
ns, err := opts.Namespace()
if err != nil {
return errors.Wrapf(err, "Unable to access HCP project")
return err
}

var readmeTpl []byte
if opts.ReadmeMarkdownTemplateFile != "" {
readmeTpl, err = os.ReadFile(opts.ReadmeMarkdownTemplateFile)
if err != nil {
return errors.Wrapf(err, "failed to read README markdown template file %q", opts.ReadmeMarkdownTemplateFile)
return errors.Wrapf(err, "%s failed to read README markdown template file %q",
opts.IO.ColorScheme().FailureIcon(),
opts.ReadmeMarkdownTemplateFile)
}
}

Expand All @@ -160,10 +162,16 @@ func addOnDefinitionCreate(opts *AddOnDefinitionOpts) error {
Context: opts.Ctx,
}, nil)
if err != nil {
return errors.Wrapf(err, "failed to create add-on definition %q", opts.Name)
return errors.Wrapf(err, "%s failed to create add-on definition %q",
opts.IO.ColorScheme().FailureIcon(),
opts.Name,
)
}

fmt.Fprintf(opts.IO.Err(), "Add-on definition %q created.", opts.Name)
fmt.Fprintf(opts.IO.Err(), "%s Add-on definition %q created.\n",
opts.IO.ColorScheme().SuccessIcon(),
opts.Name,
)

return nil
}
10 changes: 8 additions & 2 deletions internal/commands/waypoint/add-ons/definitions/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ func addOnDefinitionDelete(opts *AddOnDefinitionOpts) error {
}, nil,
)
if err != nil {
return errors.Wrapf(err, "failed to delete add-on definition %q", opts.Name)
return errors.Wrapf(err, "%s failed to delete add-on definition %q",
opts.IO.ColorScheme().FailureIcon(),
opts.Name,
)
}

fmt.Fprintf(opts.IO.Err(), "Add-on definition %q deleted.", opts.Name)
fmt.Fprintf(opts.IO.Err(), "%s Add-on definition %q deleted.\n",
opts.IO.ColorScheme().SuccessIcon(),
opts.Name,
)

return nil
}
8 changes: 6 additions & 2 deletions internal/commands/waypoint/add-ons/definitions/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func addOnDefinitionsList(opts *AddOnDefinitionOpts) error {
}, nil,
)
if err != nil {
return errors.Wrap(err, "failed to list add-on definitions")
return errors.Wrapf(err, "%s failed to list add-on definitions",
opts.IO.ColorScheme().FailureIcon(),
)
}

addOnDefinitions = append(addOnDefinitions, listResp.GetPayload().AddOnDefinitions...)
Expand All @@ -67,7 +69,9 @@ func addOnDefinitionsList(opts *AddOnDefinitionOpts) error {
PaginationNextPageToken: &listResp.GetPayload().Pagination.NextPageToken,
}, nil)
if err != nil {
return errors.Wrapf(err, "failed to list paginated add-on definitions")
return errors.Wrapf(err, "%s failed to list paginated add-on definitions",
opts.IO.ColorScheme().FailureIcon(),
)
}

addOnDefinitions = append(addOnDefinitions, listResp.GetPayload().AddOnDefinitions...)
Expand Down
7 changes: 5 additions & 2 deletions internal/commands/waypoint/add-ons/definitions/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ $ hcp waypoint add-ons definitions read -n my-addon-definition
func addOnDefinitionRead(opts *AddOnDefinitionOpts) error {
ns, err := opts.Namespace()
if err != nil {
return errors.Wrap(err, "unable to access HCP project")
return err
}

getResp, err := opts.WS.WaypointServiceGetAddOnDefinition2(
Expand All @@ -64,7 +64,10 @@ func addOnDefinitionRead(opts *AddOnDefinitionOpts) error {
}, nil,
)
if err != nil {
return errors.Wrapf(err, "failed to get add-on definition %q", opts.Name)
return errors.Wrapf(err, "%s failed to get add-on definition %q",
opts.IO.ColorScheme().FailureIcon(),
opts.Name,
)
}

getRespPayload := getResp.GetPayload()
Expand Down
16 changes: 12 additions & 4 deletions internal/commands/waypoint/add-ons/definitions/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,17 @@ $ hcp waypoint add-ons definitions update -n=my-add-on-definition \
func addOnDefinitionUpdate(opts *AddOnDefinitionOpts) error {
ns, err := opts.Namespace()
if err != nil {
return errors.Wrap(err, "unable to access HCP project")
return err
}

var readmeTpl []byte
if opts.ReadmeMarkdownTemplateFile != "" {
readmeTpl, err = os.ReadFile(opts.ReadmeMarkdownTemplateFile)
if err != nil {
return errors.Wrapf(err, "failed to read README markdown template file %q", opts.ReadmeMarkdownTemplateFile)
return errors.Wrapf(err, "%s failed to read README markdown template file %q",
opts.IO.ColorScheme().FailureIcon(),
opts.ReadmeMarkdownTemplateFile,
)
}
}

Expand All @@ -151,10 +154,15 @@ func addOnDefinitionUpdate(opts *AddOnDefinitionOpts) error {
}, nil,
)
if err != nil {
return errors.Wrapf(err, "failed to update add-on definition %q", opts.Name)
return errors.Wrapf(err, "%s failed to update add-on definition %q",
opts.IO.ColorScheme().FailureIcon(),
opts.Name,
)
}

fmt.Fprintf(opts.IO.Err(), "Add-on definition %q updated.", opts.Name)
fmt.Fprintf(opts.IO.Err(), "%s Add-on definition %q updated.\n",
opts.IO.ColorScheme().SuccessIcon(),
opts.Name)

return nil
}
12 changes: 9 additions & 3 deletions internal/commands/waypoint/applications/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ $ hcp waypoint application create -n my-application -t my-templates
func applicationCreate(opts *ApplicationOpts) error {
ns, err := opts.Namespace()
if err != nil {
return errors.Wrap(err, "unable to access HCP project")
return err
}

actionConfigs := make([]*models.HashicorpCloudWaypointActionCfgRef, len(opts.ActionConfigNames))
Expand All @@ -95,10 +95,16 @@ func applicationCreate(opts *ApplicationOpts) error {
},
}, nil)
if err != nil {
return errors.Wrapf(err, "failed to create application %q", opts.Name)
return errors.Wrapf(err, "%s failed to create application %q",
opts.IO.ColorScheme().FailureIcon(),
opts.Name,
)
}

fmt.Fprintf(opts.IO.Err(), "Application %q created.", opts.Name)
fmt.Fprintf(opts.IO.Err(), "%s Application %q created.\n",
opts.IO.ColorScheme().SuccessIcon(),
opts.Name,
)

return nil
}
16 changes: 11 additions & 5 deletions internal/commands/waypoint/applications/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,18 @@ $ hcp waypoint applications destroy -n my-application
func applicationDestroy(opts *ApplicationOpts) error {
ns, err := opts.Namespace()
if err != nil {
return errors.Wrap(err, "failed to get namespace")
return err
}

if opts.IO.CanPrompt() {
ok, err := opts.IO.PromptConfirm(
"The HCP Waypoint application will be deleted.\n\n" +
"Do you want to continue")
if err != nil {
return fmt.Errorf("failed to retrieve confirmation: %w", err)
return errors.Wrapf(err, "%s failed to prompt for confirmation",
opts.IO.ColorScheme().FailureIcon(),
)
}

if !ok {
return nil
}
Expand All @@ -79,10 +80,15 @@ func applicationDestroy(opts *ApplicationOpts) error {
}, nil,
)
if err != nil {
return errors.Wrapf(err, "failed to destroy application %q", opts.Name)
return errors.Wrapf(err, "%s failed to destroy application %q",
opts.IO.ColorScheme().FailureIcon(),
opts.Name,
)
}

fmt.Fprintf(opts.IO.Err(), "Application %q destroyed.", opts.Name)
fmt.Fprintf(opts.IO.Err(), "%s Application %q destroyed.\n",
opts.IO.ColorScheme().SuccessIcon(),
opts.Name)

return nil
}
8 changes: 5 additions & 3 deletions internal/commands/waypoint/applications/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func NewCmdApplicationsList(ctx *cmd.Context, opts *ApplicationOpts) *cmd.Command {
cmd := &cmd.Command{
Name: "list",
ShortHelp: "List HCP Waypoint applications.",
ShortHelp: "List all HCP Waypoint applications.",
LongHelp: heredoc.New(ctx.IO).Must(`
The {{ template "mdCodeOrBold" "hcp waypoint applications list" }} command lists all
HCP Waypoint applications.
Expand All @@ -30,7 +30,7 @@ func NewCmdApplicationsList(ctx *cmd.Context, opts *ApplicationOpts) *cmd.Comman
func applicationsList(opts *ApplicationOpts) error {
ns, err := opts.Namespace()
if err != nil {
return errors.Wrap(err, "unable to access HCP project")
return err
}

resp, err := opts.WS.WaypointServiceListApplications(
Expand All @@ -40,7 +40,9 @@ func applicationsList(opts *ApplicationOpts) error {
}, nil,
)
if err != nil {
return errors.Wrap(err, "failed to list applications")
return errors.Wrapf(err, "%s failed to list applications",
opts.IO.ColorScheme().FailureIcon(),
)
}

return opts.Output.Show(resp.GetPayload().Applications, format.Pretty)
Expand Down
9 changes: 6 additions & 3 deletions internal/commands/waypoint/applications/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func NewCmdApplicationsRead(ctx *cmd.Context, opts *ApplicationOpts) *cmd.Command {
cmd := &cmd.Command{
Name: "read",
ShortHelp: "Read an HCP Waypoint application.",
ShortHelp: "Read details about an HCP Waypoint application.",
LongHelp: heredoc.New(ctx.IO).Must(`
The {{ template "mdCodeOrBold" "hcp waypoint applications read" }} command lets you read
details about an HCP Waypoint application.
Expand Down Expand Up @@ -52,7 +52,7 @@ details about an HCP Waypoint application.
func applicationRead(opts *ApplicationOpts) error {
ns, err := opts.Namespace()
if err != nil {
return errors.Wrap(err, "failed to get namespace")
return err
}

getResp, err := opts.WS.WaypointServiceGetApplication2(
Expand All @@ -63,7 +63,10 @@ func applicationRead(opts *ApplicationOpts) error {
}, nil,
)
if err != nil {
return errors.Wrapf(err, "failed to get application %q", opts.Name)
return errors.Wrapf(err, "%s failed to get application %q",
opts.IO.ColorScheme().FailureIcon(),
opts.Name,
)
}

return opts.Output.Show(getResp.GetPayload().Application, format.Pretty)
Expand Down
17 changes: 13 additions & 4 deletions internal/commands/waypoint/applications/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ $ hcp waypoint applications update -n my-application --action-config-name my-act
func applicationUpdate(opts *ApplicationOpts) error {
ns, err := opts.Namespace()
if err != nil {
return errors.Wrap(err, "failed to get namespace")
return err
}

var acrs []*models.HashicorpCloudWaypointActionCfgRef
Expand All @@ -86,7 +86,10 @@ func applicationUpdate(opts *ApplicationOpts) error {
if opts.ReadmeMarkdownFile != "" {
readme, err = os.ReadFile(opts.ReadmeMarkdownFile)
if err != nil {
return errors.Wrapf(err, "failed to read README markdown file %q", opts.ReadmeMarkdownFile)
return errors.Wrapf(err,
"%s failed to read README markdown file %q",
opts.IO.ColorScheme().FailureIcon(),
opts.ReadmeMarkdownFile)
}
}

Expand All @@ -102,10 +105,16 @@ func applicationUpdate(opts *ApplicationOpts) error {
}, nil,
)
if err != nil {
return errors.Wrapf(err, "failed to update application %q", opts.Name)
return errors.Wrapf(err, "%s failed to update application %q",
opts.IO.ColorScheme().FailureIcon(),
opts.Name,
)
}

fmt.Fprintf(opts.IO.Err(), "Application %q updated.", opts.Name)
fmt.Fprintf(opts.IO.Err(), "%s Application %q updated.\n",
opts.IO.ColorScheme().SuccessIcon(),
opts.Name,
)

return nil
}
4 changes: 3 additions & 1 deletion internal/commands/waypoint/opts/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func (w *WaypointOpts) Namespace() (*models.HashicorpCloudWaypointNamespace, err
Context: w.Ctx,
}, nil)
if err != nil {
return nil, errors.Wrapf(err, "Unable to access HCP project")
return nil, errors.Wrapf(err, "%s Unable to access HCP project",
w.IO.ColorScheme().FailureIcon(),
)
}

return resp.Payload.Namespace, nil
Expand Down
19 changes: 15 additions & 4 deletions internal/commands/waypoint/templates/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ $ hcp waypoint templates create -n my-template \
func templateCreate(opts *TemplateOpts) error {
ns, err := opts.Namespace()
if err != nil {
return errors.Wrapf(err, "unable to access HCP project")
return err
}

var tags []*models.HashicorpCloudWaypointTag
Expand All @@ -154,7 +154,10 @@ func templateCreate(opts *TemplateOpts) error {
if opts.ReadmeMarkdownTemplateFile != "" {
readmeTpl, err = os.ReadFile(opts.ReadmeMarkdownTemplateFile)
if err != nil {
return errors.Wrapf(err, "failed to read README markdown template file %q", opts.ReadmeMarkdownTemplateFile)
return errors.Wrapf(err, "%s failed to read README markdown template file %q",
opts.IO.ColorScheme().FailureIcon(),
opts.ReadmeMarkdownTemplateFile,
)
}
}

Expand Down Expand Up @@ -182,10 +185,18 @@ func templateCreate(opts *TemplateOpts) error {
Context: opts.Ctx,
}, nil)
if err != nil {
return errors.Wrapf(err, "failed to create template %q", opts.Name)
return errors.Wrapf(
err,
"%s failed to create template %q",
opts.IO.ColorScheme().FailureIcon(),
opts.Name,
)
}

fmt.Fprintf(opts.IO.Err(), "Template %q created.", opts.Name)
fmt.Fprintf(opts.IO.Err(), "%s Template %q created.\n",
opts.IO.ColorScheme().SuccessIcon(),
opts.Name,
)

return nil
}
7 changes: 5 additions & 2 deletions internal/commands/waypoint/templates/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ existing HCP Waypoint templates.
func templateDelete(opts *TemplateOpts) error {
ns, err := opts.Namespace()
if err != nil {
return errors.Wrapf(err, "unable to access HCP project")
return err
}

_, err = opts.WS.WaypointServiceDeleteApplicationTemplate2(
Expand All @@ -61,7 +61,10 @@ func templateDelete(opts *TemplateOpts) error {
return errors.Wrapf(err, "failed to delete template %q", opts.Name)
}

fmt.Fprintf(opts.IO.Err(), "Template %q deleted.", opts.Name)
fmt.Fprintf(opts.IO.Err(), "%s Template %q deleted.\n",
opts.IO.ColorScheme().SuccessIcon(),
opts.Name,
)

return nil
}
Loading

0 comments on commit aab8602

Please sign in to comment.