diff options
-rw-r--r-- | commands/commandeer.go | 4 | ||||
-rw-r--r-- | commands/commands.go | 39 | ||||
-rw-r--r-- | commands/hugo.go | 5 | ||||
-rw-r--r-- | utils/utils.go | 59 |
4 files changed, 42 insertions, 65 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go index 051787f6e..3ff0b6426 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -24,8 +24,6 @@ import ( "github.com/spf13/cobra" - "github.com/gohugoio/hugo/utils" - "github.com/spf13/afero" "github.com/gohugoio/hugo/hugolib" @@ -308,7 +306,7 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { cacheDir = cacheDir + helpers.FilePathSeparator } isDir, err := helpers.DirExists(cacheDir, sourceFs) - utils.CheckErr(cfg.Logger, err) + checkErr(cfg.Logger, err) if !isDir { mkdir(cacheDir) } diff --git a/commands/commands.go b/commands/commands.go index 74bc709cc..88939e600 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -14,9 +14,12 @@ package commands import ( + "os" + "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/helpers" "github.com/spf13/cobra" + jww "github.com/spf13/jwalterweatherman" "github.com/spf13/nitro" ) @@ -241,3 +244,39 @@ func (cc *hugoBuilderCommon) handleFlags(cmd *cobra.Command) { _ = cmd.Flags().SetAnnotation("destination", cobra.BashCompSubdirsInDir, []string{}) _ = cmd.Flags().SetAnnotation("theme", cobra.BashCompSubdirsInDir, []string{"themes"}) } + +func checkErr(logger *jww.Notepad, err error, s ...string) { + if err == nil { + return + } + if len(s) == 0 { + logger.CRITICAL.Println(err) + return + } + for _, message := range s { + logger.ERROR.Println(message) + } + logger.ERROR.Println(err) +} + +func stopOnErr(logger *jww.Notepad, err error, s ...string) { + if err == nil { + return + } + + defer os.Exit(-1) + + if len(s) == 0 { + newMessage := err.Error() + // Printing an empty string results in a error with + // no message, no bueno. + if newMessage != "" { + logger.CRITICAL.Println(newMessage) + } + } + for _, message := range s { + if message != "" { + logger.CRITICAL.Println(message) + } + } +} diff --git a/commands/hugo.go b/commands/hugo.go index 980189c47..312767499 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -43,7 +43,6 @@ import ( "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/hugolib" "github.com/gohugoio/hugo/livereload" - "github.com/gohugoio/hugo/utils" "github.com/gohugoio/hugo/watcher" "github.com/spf13/afero" "github.com/spf13/cobra" @@ -351,7 +350,7 @@ func (c *commandeer) build() error { c.Logger.FEEDBACK.Println("Watching for changes in", c.hugo.PathSpec.AbsPathify(c.Cfg.GetString("contentDir"))) c.Logger.FEEDBACK.Println("Press Ctrl+C to stop") watcher, err := c.newWatcher(watchDirs...) - utils.CheckErr(c.Logger, err) + checkErr(c.Logger, err) defer watcher.Close() var sigs = make(chan os.Signal) @@ -813,7 +812,7 @@ func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) { c.Logger.FEEDBACK.Printf("Syncing all static files\n") _, err := c.copyStatic() if err != nil { - utils.StopOnErr(c.Logger, err, "Error copying static files to publish dir") + stopOnErr(c.Logger, err, "Error copying static files to publish dir") } } else { if err := staticSyncer.syncsStaticEvents(staticEvents); err != nil { diff --git a/utils/utils.go b/utils/utils.go deleted file mode 100644 index 87357a26e..000000000 --- a/utils/utils.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2016 The Hugo Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package utils - -import ( - "os" - - jww "github.com/spf13/jwalterweatherman" -) - -// CheckErr logs the messages given and then the error. -// TODO(bep) Remove this package. -func CheckErr(logger *jww.Notepad, err error, s ...string) { - if err == nil { - return - } - if len(s) == 0 { - logger.CRITICAL.Println(err) - return - } - for _, message := range s { - logger.ERROR.Println(message) - } - logger.ERROR.Println(err) -} - -// StopOnErr exits on any error after logging it. -func StopOnErr(logger *jww.Notepad, err error, s ...string) { - if err == nil { - return - } - - defer os.Exit(-1) - - if len(s) == 0 { - newMessage := err.Error() - // Printing an empty string results in a error with - // no message, no bueno. - if newMessage != "" { - logger.CRITICAL.Println(newMessage) - } - } - for _, message := range s { - if message != "" { - logger.CRITICAL.Println(message) - } - } -} |