From 3f0f7eed68f44486c1e053bbce25c46c1d52a12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 2 Dec 2015 11:42:53 +0100 Subject: Improve error handling in commands Cobra, the CLI commander in use in Hugo, has some long awaited improvements in the error handling department. This enables a more centralized error handling approach. This commit introduces that by changing all the command funcs to `RunE`: * The core part of the error logging, usage logging and `os.Exit(-1)` is now performed in one place and that one place only. * The usage text is now only shown on invalid arguments etc. (user errors) Fixes #1502 --- commands/genman.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'commands/genman.go') diff --git a/commands/genman.go b/commands/genman.go index 68a98a46d..a842b49b8 100644 --- a/commands/genman.go +++ b/commands/genman.go @@ -18,7 +18,7 @@ var genmanCmd = &cobra.Command{ command-line interface. By default, it creates the man page files in the "man" directory under the current directory.`, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { header := &cobra.GenManHeader{ Section: "1", Manual: "Hugo Manual", @@ -37,6 +37,8 @@ in the "man" directory under the current directory.`, cmd.Root().GenManTree(header, genmandir) jww.FEEDBACK.Println("Done.") + + return nil }, } -- cgit v1.2.3