From fdc56c5b36c69d92a2c97d729fa259ad9baf7308 Mon Sep 17 00:00:00 2001 From: Charlie Voiselle <464492+angrycub@users.noreply.github.com> Date: Thu, 26 Oct 2023 15:43:00 -0400 Subject: [PATCH] Make argument errors consistent across commands --- internal/cli/deps_vendor.go | 7 ++++--- internal/cli/destroy.go | 2 -- internal/cli/generate_pack.go | 3 ++- internal/cli/generate_registry.go | 3 ++- internal/cli/generate_varfile.go | 2 -- internal/cli/info.go | 2 -- internal/cli/list.go | 2 ++ internal/cli/plan.go | 2 +- internal/cli/registry_add.go | 3 ++- internal/cli/registry_delete.go | 3 ++- internal/cli/registry_list.go | 4 +++- internal/cli/render.go | 5 ++--- internal/cli/run.go | 4 +--- internal/cli/version.go | 7 ++++++- 14 files changed, 27 insertions(+), 22 deletions(-) diff --git a/internal/cli/deps_vendor.go b/internal/cli/deps_vendor.go index 296f1646..b6148a87 100644 --- a/internal/cli/deps_vendor.go +++ b/internal/cli/deps_vendor.go @@ -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 } @@ -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. `, }) diff --git a/internal/cli/destroy.go b/internal/cli/destroy.go index 2c68d5ef..402c3379 100644 --- a/internal/cli/destroy.go +++ b/internal/cli/destroy.go @@ -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 diff --git a/internal/cli/generate_pack.go b/internal/cli/generate_pack.go index 2b7062ca..c794ca84 100644 --- a/internal/cli/generate_pack.go +++ b/internal/cli/generate_pack.go @@ -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 } diff --git a/internal/cli/generate_registry.go b/internal/cli/generate_registry.go index c8f67f0a..f56f5a19 100644 --- a/internal/cli/generate_registry.go +++ b/internal/cli/generate_registry.go @@ -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 } diff --git a/internal/cli/generate_varfile.go b/internal/cli/generate_varfile.go index e88f07c3..f98a724e 100644 --- a/internal/cli/generate_varfile.go +++ b/internal/cli/generate_varfile.go @@ -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 } diff --git a/internal/cli/info.go b/internal/cli/info.go index dc1784c8..8f6341c6 100644 --- a/internal/cli/info.go +++ b/internal/cli/info.go @@ -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 } diff --git a/internal/cli/list.go b/internal/cli/list.go index 081ae3b6..cb8a1632 100644 --- a/internal/cli/list.go +++ b/internal/cli/list.go @@ -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 } diff --git a/internal/cli/plan.go b/internal/cli/plan.go index a92cc03f..92d2f68a 100644 --- a/internal/cli/plan.go +++ b/internal/cli/plan.go @@ -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] diff --git a/internal/cli/registry_add.go b/internal/cli/registry_add.go index ed235973..8236a61c 100644 --- a/internal/cli/registry_add.go +++ b/internal/cli/registry_add.go @@ -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 } diff --git a/internal/cli/registry_delete.go b/internal/cli/registry_delete.go index e89ff73b..165bc738 100644 --- a/internal/cli/registry_delete.go +++ b/internal/cli/registry_delete.go @@ -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 } diff --git a/internal/cli/registry_list.go b/internal/cli/registry_list.go index ff73166c..051e2add 100644 --- a/internal/cli/registry_list.go +++ b/internal/cli/registry_list.go @@ -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 } diff --git a/internal/cli/render.go b/internal/cli/render.go index 8763dddd..f25e234d 100644 --- a/internal/cli/render.go +++ b/internal/cli/render.go @@ -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 } diff --git a/internal/cli/run.go b/internal/cli/run.go index 01caf154..fd5fd3af 100644 --- a/internal/cli/run.go +++ b/internal/cli/run.go @@ -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(), diff --git a/internal/cli/version.go b/internal/cli/version.go index 3e246c25..6186888c 100644 --- a/internal/cli/version.go +++ b/internal/cli/version.go @@ -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