From 9070806f8d96b04ebce79cf434b1464a17dec78c Mon Sep 17 00:00:00 2001 From: Roxie Gibson Date: Mon, 2 Aug 2021 05:58:47 +0100 Subject: [PATCH] refactor: deal with err from ShowSubcommandHelp --- cli/internal/errors.go | 5 ++++- cli/recipe/recipe.go | 6 ++---- cli/server/init.go | 3 +-- cli/server/new.go | 3 +-- cli/server/remove.go | 3 +-- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cli/internal/errors.go b/cli/internal/errors.go index 49070b5c..036eed5a 100644 --- a/cli/internal/errors.go +++ b/cli/internal/errors.go @@ -9,7 +9,10 @@ import ( // showSubcommandHelpAndError exits the program on error, logs the error to the terminal, and shows the help command. func ShowSubcommandHelpAndError(c *cli.Context, err interface{}) { - cli.ShowSubcommandHelp(c) + if err2 := cli.ShowSubcommandHelp(c); err2 != nil { + // go-critic wants me to check this error but if this throws an error while we throw an error that would be annoying + logrus.Error(err2) + } logrus.Error(err) os.Exit(1) } diff --git a/cli/recipe/recipe.go b/cli/recipe/recipe.go index 65bb899b..f50a8712 100644 --- a/cli/recipe/recipe.go +++ b/cli/recipe/recipe.go @@ -46,8 +46,7 @@ var recipeVersionCommand = &cli.Command{ Action: func(c *cli.Context) error { recipe := c.Args().First() if recipe == "" { - cli.ShowSubcommandHelp(c) - return nil + return cli.ShowSubcommandHelp(c) } catalogue, err := catalogue.ReadAppsCatalogue() @@ -82,8 +81,7 @@ var recipeCreateCommand = &cli.Command{ Action: func(c *cli.Context) error { recipe := c.Args().First() if recipe == "" { - cli.ShowSubcommandHelp(c) - return nil + return cli.ShowSubcommandHelp(c) } directory := path.Join(config.APPS_DIR, recipe) diff --git a/cli/server/init.go b/cli/server/init.go index 00953f89..f8c7f78b 100644 --- a/cli/server/init.go +++ b/cli/server/init.go @@ -26,8 +26,7 @@ later for more advanced use cases. Action: func(c *cli.Context) error { host := c.Args().First() if host == "" { - cli.ShowSubcommandHelp(c) - return nil + return cli.ShowSubcommandHelp(c) } cl, err := client.NewClientWithContext(host) diff --git a/cli/server/new.go b/cli/server/new.go index d72e85bf..18a6c4d3 100644 --- a/cli/server/new.go +++ b/cli/server/new.go @@ -66,8 +66,7 @@ environment variable or otherwise passing the "--env/-e" flag. Action: func(c *cli.Context) error { name := c.Args().First() if name == "" { - cli.ShowSubcommandHelp(c) - return nil + return cli.ShowSubcommandHelp(c) } ctx := context.Background() diff --git a/cli/server/remove.go b/cli/server/remove.go index efef2246..4c14d73e 100644 --- a/cli/server/remove.go +++ b/cli/server/remove.go @@ -14,8 +14,7 @@ var serverRemoveCommand = &cli.Command{ Action: func(c *cli.Context) error { server := c.Args().First() if server == "" { - cli.ShowSubcommandHelp(c) - return nil + return cli.ShowSubcommandHelp(c) } if err := client.DeleteContext(server); err != nil { logrus.Fatal(err)