mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Get rid of the utils package
This commit is contained in:
parent
4e1d0cd9f1
commit
062510cf1f
4 changed files with 42 additions and 65 deletions
|
@ -24,8 +24,6 @@ import (
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/utils"
|
|
||||||
|
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/hugolib"
|
"github.com/gohugoio/hugo/hugolib"
|
||||||
|
@ -308,7 +306,7 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error {
|
||||||
cacheDir = cacheDir + helpers.FilePathSeparator
|
cacheDir = cacheDir + helpers.FilePathSeparator
|
||||||
}
|
}
|
||||||
isDir, err := helpers.DirExists(cacheDir, sourceFs)
|
isDir, err := helpers.DirExists(cacheDir, sourceFs)
|
||||||
utils.CheckErr(cfg.Logger, err)
|
checkErr(cfg.Logger, err)
|
||||||
if !isDir {
|
if !isDir {
|
||||||
mkdir(cacheDir)
|
mkdir(cacheDir)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,12 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/config"
|
"github.com/gohugoio/hugo/config"
|
||||||
"github.com/gohugoio/hugo/helpers"
|
"github.com/gohugoio/hugo/helpers"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
|
|
||||||
"github.com/spf13/nitro"
|
"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("destination", cobra.BashCompSubdirsInDir, []string{})
|
||||||
_ = cmd.Flags().SetAnnotation("theme", cobra.BashCompSubdirsInDir, []string{"themes"})
|
_ = 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -43,7 +43,6 @@ import (
|
||||||
"github.com/gohugoio/hugo/helpers"
|
"github.com/gohugoio/hugo/helpers"
|
||||||
"github.com/gohugoio/hugo/hugolib"
|
"github.com/gohugoio/hugo/hugolib"
|
||||||
"github.com/gohugoio/hugo/livereload"
|
"github.com/gohugoio/hugo/livereload"
|
||||||
"github.com/gohugoio/hugo/utils"
|
|
||||||
"github.com/gohugoio/hugo/watcher"
|
"github.com/gohugoio/hugo/watcher"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
"github.com/spf13/cobra"
|
"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("Watching for changes in", c.hugo.PathSpec.AbsPathify(c.Cfg.GetString("contentDir")))
|
||||||
c.Logger.FEEDBACK.Println("Press Ctrl+C to stop")
|
c.Logger.FEEDBACK.Println("Press Ctrl+C to stop")
|
||||||
watcher, err := c.newWatcher(watchDirs...)
|
watcher, err := c.newWatcher(watchDirs...)
|
||||||
utils.CheckErr(c.Logger, err)
|
checkErr(c.Logger, err)
|
||||||
defer watcher.Close()
|
defer watcher.Close()
|
||||||
|
|
||||||
var sigs = make(chan os.Signal)
|
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")
|
c.Logger.FEEDBACK.Printf("Syncing all static files\n")
|
||||||
_, err := c.copyStatic()
|
_, err := c.copyStatic()
|
||||||
if err != nil {
|
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 {
|
} else {
|
||||||
if err := staticSyncer.syncsStaticEvents(staticEvents); err != nil {
|
if err := staticSyncer.syncsStaticEvents(staticEvents); err != nil {
|
||||||
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue