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
This commit is contained in:
Bjørn Erik Pedersen
2015-12-02 11:42:53 +01:00
committed by Anthony Fok
parent 6959b7fa80
commit 3f0f7eed68
17 changed files with 219 additions and 155 deletions

View File

@@ -254,9 +254,11 @@ func (s *Site) Build() (err error) {
return nil
}
func (s *Site) Analyze() {
s.Process()
s.ShowPlan(os.Stdout)
func (s *Site) Analyze() error {
if err := s.Process(); err != nil {
return err
}
return s.ShowPlan(os.Stdout)
}
func (s *Site) prepTemplates() {