Skip to content

Commit

Permalink
Make argument errors consistent across commands
Browse files Browse the repository at this point in the history
  • Loading branch information
angrycub committed Oct 26, 2023
1 parent b5767f8 commit fdc56c5
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 22 deletions.
7 changes: 4 additions & 3 deletions internal/cli/deps_vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func (d *depsVendorCommand) Run(args []string) int {
WithNoConfig(),
WithClient(false),
); err != nil {
d.ui.ErrorWithContext(err, "error parsing args or flags")
d.ui.ErrorWithContext(err, ErrParsingArgsOrFlags)
d.ui.Info(d.helpUsageMessage())
return 1
}

Expand All @@ -58,8 +59,8 @@ func (d *depsVendorCommand) Flags() *flag.Sets {
Name: "path",
Target: &d.targetPath,
Default: "",
Usage: `Full path to the pack which contains dependencies to be
vendored. All the dependencies will then be downloaded
Usage: `Full path to the pack which contains dependencies to be
vendored. All the dependencies will then be downloaded
into a 'deps/' subdirectory of that path. `,
})

Expand Down
2 changes: 0 additions & 2 deletions internal/cli/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ func (c *DestroyCommand) Run(args []string) int {
WithFlags(c.Flags()),
WithNoConfig(),
); err != nil {

c.ui.ErrorWithContext(err, ErrParsingArgsOrFlags)
c.ui.Info(c.helpUsageMessage())

return 1
} else {
// This needs to be in an else block so that it doesn't try to run while
Expand Down
3 changes: 2 additions & 1 deletion internal/cli/generate_pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func (c *GeneratePackCommand) Run(args []string) int {
WithNoConfig(),
WithClient(false),
); err != nil {
c.ui.ErrorWithContext(err, "error parsing args or flags")
c.ui.ErrorWithContext(err, ErrParsingArgsOrFlags)
c.ui.Info(c.helpUsageMessage())
return 1
}

Expand Down
3 changes: 2 additions & 1 deletion internal/cli/generate_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func (c *GenerateRegistryCommand) Run(args []string) int {
WithNoConfig(),
WithClient(false),
); err != nil {
c.ui.ErrorWithContext(err, "error parsing args or flags")
c.ui.ErrorWithContext(err, ErrParsingArgsOrFlags)
c.ui.Info(c.helpUsageMessage())
return 1
}

Expand Down
2 changes: 0 additions & 2 deletions internal/cli/generate_varfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,8 @@ func (c *generateVarFileCommand) Run(args []string) int {
WithExactArgs(1, args),
WithFlags(c.Flags()),
WithNoConfig()); err != nil {

c.ui.ErrorWithContext(err, ErrParsingArgsOrFlags)
c.ui.Info(c.helpUsageMessage())

return 1
}

Expand Down
2 changes: 0 additions & 2 deletions internal/cli/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ func (c *InfoCommand) Run(args []string) int {
WithFlags(c.Flags()),
WithNoConfig(),
); err != nil {

c.ui.ErrorWithContext(err, ErrParsingArgsOrFlags)
c.ui.Info(c.helpUsageMessage())

return 1
}

Expand Down
2 changes: 2 additions & 0 deletions internal/cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func (c *ListCommand) Run(args []string) int {
WithNoConfig(),
WithClient(false),
); err != nil {
c.ui.ErrorWithContext(err, ErrParsingArgsOrFlags)
c.ui.Info(c.helpUsageMessage())
return 1
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c *PlanCommand) Run(args []string) int {
); err != nil {
c.ui.ErrorWithContext(err, ErrParsingArgsOrFlags)
c.ui.Info(c.helpUsageMessage())
return 255
return c.exitCodeError
}

c.packConfig.Name = c.args[0]
Expand Down
3 changes: 2 additions & 1 deletion internal/cli/registry_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func (c *RegistryAddCommand) Run(args []string) int {
WithNoConfig(),
WithClient(false),
); err != nil {
c.ui.ErrorWithContext(err, "error parsing args or flags")
c.ui.ErrorWithContext(err, ErrParsingArgsOrFlags)
c.ui.Info(c.helpUsageMessage())
return 1
}

Expand Down
3 changes: 2 additions & 1 deletion internal/cli/registry_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func (c *RegistryDeleteCommand) Run(args []string) int {
WithNoConfig(),
WithClient(false),
); err != nil {
c.ui.ErrorWithContext(err, "error parsing args or flags")
c.ui.ErrorWithContext(err, ErrParsingArgsOrFlags)
c.ui.Info(c.helpUsageMessage())
return 1
}

Expand Down
4 changes: 3 additions & 1 deletion internal/cli/registry_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ type RegistryListCommand struct {

func (c *RegistryListCommand) Run(args []string) int {
c.cmdKey = "registry list"
// Initialize. If we fail, we just exit since Init handles the UI.

if err := c.Init(
WithNoArgs(args),
WithNoConfig(),
WithClient(false),
); err != nil {
c.ui.ErrorWithContext(err, ErrParsingArgsOrFlags)
c.ui.Info(c.helpUsageMessage())
return 1
}

Expand Down
5 changes: 2 additions & 3 deletions internal/cli/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,10 @@ func (c *RenderCommand) Run(args []string) int {
if err := c.Init(
WithExactArgs(1, args),
WithFlags(c.Flags()),
WithNoConfig()); err != nil {

WithNoConfig(),
); err != nil {
c.ui.ErrorWithContext(err, ErrParsingArgsOrFlags)
c.ui.Info(c.helpUsageMessage())

return 1
}

Expand Down
4 changes: 1 addition & 3 deletions internal/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ type RunCommand struct {
}

func (c *RunCommand) Run(args []string) int {
var err error

c.cmdKey = "run" // Add cmdKey here to print out helpUsageMessage on Init error

// Initialize. If we fail, we just exit since Init handles the UI.
if err = c.Init(
if err := c.Init(
WithExactArgs(1, args),
WithFlags(c.Flags()),
WithNoConfig(),
Expand Down
7 changes: 6 additions & 1 deletion internal/cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ func (c *VersionCommand) Run(args []string) int {
c.cmdKey = "version"

// Initialize. If we fail, we just exit since Init handles the UI.
if err := c.Init(WithNoArgs(args), WithFlags(flagSet), WithNoConfig(), WithClient(false)); err != nil {
if err := c.Init(
WithNoArgs(args),
WithFlags(flagSet),
WithNoConfig(),
WithClient(false),
); err != nil {
c.ui.ErrorWithContext(err, ErrParsingArgsOrFlags)
c.ui.Info(c.helpUsageMessage())
return 1
Expand Down

0 comments on commit fdc56c5

Please sign in to comment.