summaryrefslogtreecommitdiffstats
path: root/commands/genautocomplete.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2015-12-02 11:42:53 +0100
committerAnthony Fok <foka@debian.org>2015-12-02 07:07:05 -0700
commit3f0f7eed68f44486c1e053bbce25c46c1d52a12f (patch)
tree4bafd37bcd2ede6fb1c7f5838679a345dae83668 /commands/genautocomplete.go
parent6959b7fa80f22aead6fa8c9b8ff3c4b8cc222a30 (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/genautocomplete.go')
-rw-r--r--commands/genautocomplete.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/commands/genautocomplete.go b/commands/genautocomplete.go
index b7f74fd89..54dd7563b 100644
--- a/commands/genautocomplete.go
+++ b/commands/genautocomplete.go
@@ -31,16 +31,19 @@ or just source them in directly:
$ . /etc/bash_completion`,
- Run: func(cmd *cobra.Command, args []string) {
+ RunE: func(cmd *cobra.Command, args []string) error {
if autocompleteType != "bash" {
- jww.FATAL.Fatalln("Only Bash is supported for now")
+ return newUserError("Only Bash is supported for now")
}
+
err := cmd.Root().GenBashCompletionFile(autocompleteTarget)
+
if err != nil {
- jww.FATAL.Fatalln("Failed to generate shell completion file:", err)
+ return err
} else {
jww.FEEDBACK.Println("Bash completion file for Hugo saved to", autocompleteTarget)
}
+ return nil
},
}