diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2015-12-02 11:42:53 +0100 |
---|---|---|
committer | Anthony Fok <foka@debian.org> | 2015-12-02 07:07:05 -0700 |
commit | 3f0f7eed68f44486c1e053bbce25c46c1d52a12f (patch) | |
tree | 4bafd37bcd2ede6fb1c7f5838679a345dae83668 /commands/gendoc.go | |
parent | 6959b7fa80f22aead6fa8c9b8ff3c4b8cc222a30 (diff) |
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
Diffstat (limited to 'commands/gendoc.go')
-rw-r--r-- | commands/gendoc.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/commands/gendoc.go b/commands/gendoc.go index 9589bffa4..44d09fb50 100644 --- a/commands/gendoc.go +++ b/commands/gendoc.go @@ -32,7 +32,7 @@ of Hugo's command-line interface for http://gohugo.io/. It creates one Markdown file per command with front matter suitable for rendering in Hugo.`, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { if !strings.HasSuffix(gendocdir, helpers.FilePathSeparator) { gendocdir += helpers.FilePathSeparator } @@ -55,6 +55,8 @@ for rendering in Hugo.`, jww.FEEDBACK.Println("Generating Hugo command-line documentation in", gendocdir, "...") cobra.GenMarkdownTreeCustom(cmd.Root(), gendocdir, prepender, linkHandler) jww.FEEDBACK.Println("Done.") + + return nil }, } |