summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-22 00:34:17 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-22 00:35:09 +0200
commit062510cf1f7b79aed2efe88c5b9340d009bdec0e (patch)
treef12574dd3bea39ec02986564a8a34ec5f706cd47
parent4e1d0cd9f1d43d133d669a019a84117cadd41955 (diff)
Get rid of the utils package
-rw-r--r--commands/commandeer.go4
-rw-r--r--commands/commands.go39
-rw-r--r--commands/hugo.go5
-rw-r--r--utils/utils.go59
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)
- }
- }
-}