shithub: hugo

Download patch

ref: 062510cf1f7b79aed2efe88c5b9340d009bdec0e
parent: 4e1d0cd9f1d43d133d669a019a84117cadd41955
author: Bjørn Erik Pedersen <[email protected]>
date: Sat Jul 21 20:34:17 EDT 2018

Get rid of the utils package

--- a/commands/commandeer.go
+++ b/commands/commandeer.go
@@ -24,8 +24,6 @@
 
 	"github.com/spf13/cobra"
 
-	"github.com/gohugoio/hugo/utils"
-
 	"github.com/spf13/afero"
 
 	"github.com/gohugoio/hugo/hugolib"
@@ -308,7 +306,7 @@
 			cacheDir = cacheDir + helpers.FilePathSeparator
 		}
 		isDir, err := helpers.DirExists(cacheDir, sourceFs)
-		utils.CheckErr(cfg.Logger, err)
+		checkErr(cfg.Logger, err)
 		if !isDir {
 			mkdir(cacheDir)
 		}
--- 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"
 )
@@ -240,4 +243,40 @@
 	_ = cmd.Flags().SetAnnotation("cacheDir", cobra.BashCompSubdirsInDir, []string{})
 	_ = 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)
+		}
+	}
 }
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -43,7 +43,6 @@
 	"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 @@
 		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 @@
 						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 {
--- a/utils/utils.go
+++ /dev/null
@@ -1,59 +1,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)
-		}
-	}
-}