mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-24 00:51:04 +00:00
all: Use jww instead of fmt for printing
This is an attempt to unify method for printing.
This commit is contained in:
parent
e1da7cb320
commit
120f6b0cf2
8 changed files with 32 additions and 33 deletions
|
@ -14,10 +14,10 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
)
|
||||
|
||||
var envCmd = &cobra.Command{
|
||||
|
@ -26,9 +26,9 @@ var envCmd = &cobra.Command{
|
|||
Long: `Print Hugo version and environment info. This is useful in Hugo bug reports.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
printHugoVersion()
|
||||
fmt.Printf("GOOS=%q\n", runtime.GOOS)
|
||||
fmt.Printf("GOARCH=%q\n", runtime.GOARCH)
|
||||
fmt.Printf("GOVERSION=%q\n", runtime.Version())
|
||||
jww.FEEDBACK.Printf("GOOS=%q\n", runtime.GOOS)
|
||||
jww.FEEDBACK.Printf("GOARCH=%q\n", runtime.GOARCH)
|
||||
jww.FEEDBACK.Printf("GOVERSION=%q\n", runtime.Version())
|
||||
|
||||
return nil
|
||||
},
|
||||
|
|
|
@ -415,7 +415,7 @@ func flagChanged(flags *flag.FlagSet, key string) bool {
|
|||
func watchConfig() {
|
||||
viper.WatchConfig()
|
||||
viper.OnConfigChange(func(e fsnotify.Event) {
|
||||
fmt.Println("Config file changed:", e.Name)
|
||||
jww.FEEDBACK.Println("Config file changed:", e.Name)
|
||||
// Force a full rebuild
|
||||
utils.CheckErr(reCreateAndbuildSites(true))
|
||||
if !viper.GetBool("disableLiveReload") {
|
||||
|
@ -626,7 +626,7 @@ func reCreateAndbuildSites(watching bool) (err error) {
|
|||
return err
|
||||
}
|
||||
if !quiet {
|
||||
fmt.Println("Started building sites ...")
|
||||
jww.FEEDBACK.Println("Started building sites ...")
|
||||
}
|
||||
return Hugo.Build(hugolib.BuildCfg{CreateSitesFromConfig: true, Watching: watching, PrintStats: !quiet})
|
||||
}
|
||||
|
@ -636,7 +636,7 @@ func resetAndbuildSites(watching bool) (err error) {
|
|||
return err
|
||||
}
|
||||
if !quiet {
|
||||
fmt.Println("Started building sites ...")
|
||||
jww.FEEDBACK.Println("Started building sites ...")
|
||||
}
|
||||
return Hugo.Build(hugolib.BuildCfg{ResetState: true, Watching: watching, PrintStats: !quiet})
|
||||
}
|
||||
|
@ -661,7 +661,7 @@ func buildSites(watching bool) (err error) {
|
|||
return err
|
||||
}
|
||||
if !quiet {
|
||||
fmt.Println("Started building sites ...")
|
||||
jww.FEEDBACK.Println("Started building sites ...")
|
||||
}
|
||||
return Hugo.Build(hugolib.BuildCfg{Watching: watching, PrintStats: !quiet})
|
||||
}
|
||||
|
@ -779,7 +779,7 @@ func NewWatcher(port int) error {
|
|||
|
||||
jww.FEEDBACK.Println("\nStatic file changes detected")
|
||||
const layout = "2006-01-02 15:04 -0700"
|
||||
fmt.Println(time.Now().Format(layout))
|
||||
jww.FEEDBACK.Println(time.Now().Format(layout))
|
||||
|
||||
if viper.GetBool("forceSyncStatic") {
|
||||
jww.FEEDBACK.Printf("Syncing all static files\n")
|
||||
|
@ -825,7 +825,7 @@ func NewWatcher(port int) error {
|
|||
// If we are here we already know the event took place in a static dir
|
||||
relPath, err := helpers.MakeStaticPathRelative(fromPath)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
jww.ERROR.Println(err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -882,9 +882,9 @@ func NewWatcher(port int) error {
|
|||
}
|
||||
|
||||
if len(dynamicEvents) > 0 {
|
||||
fmt.Print("\nChange detected, rebuilding site\n")
|
||||
jww.FEEDBACK.Println("\nChange detected, rebuilding site")
|
||||
const layout = "2006-01-02 15:04 -0700"
|
||||
fmt.Println(time.Now().Format(layout))
|
||||
jww.FEEDBACK.Println(time.Now().Format(layout))
|
||||
|
||||
rebuildSites(dynamicEvents)
|
||||
|
||||
|
@ -895,7 +895,7 @@ func NewWatcher(port int) error {
|
|||
}
|
||||
case err := <-watcher.Errors:
|
||||
if err != nil {
|
||||
fmt.Println("error:", err)
|
||||
jww.ERROR.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ package commands
|
|||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -90,7 +89,7 @@ func importFromJekyll(cmd *cobra.Command, args []string) error {
|
|||
return newUserError(err)
|
||||
}
|
||||
|
||||
fmt.Println("Importing...")
|
||||
jww.FEEDBACK.Println("Importing...")
|
||||
|
||||
fileCount := 0
|
||||
callback := func(path string, fi os.FileInfo, err error) error {
|
||||
|
@ -129,10 +128,10 @@ func importFromJekyll(cmd *cobra.Command, args []string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("Congratulations!", fileCount, "post(s) imported!")
|
||||
fmt.Println("Now, start Hugo by yourself:\n" +
|
||||
jww.FEEDBACK.Println("Congratulations!", fileCount, "post(s) imported!")
|
||||
jww.FEEDBACK.Println("Now, start Hugo by yourself:\n" +
|
||||
"$ git clone https://github.com/spf13/herring-cove.git " + args[1] + "/themes/herring-cove")
|
||||
fmt.Println("$ cd " + args[1] + "\n$ hugo server --theme=herring-cove")
|
||||
jww.FEEDBACK.Println("$ cd " + args[1] + "\n$ hugo server --theme=herring-cove")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/hugo/hugolib"
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
|
@ -63,7 +63,7 @@ var listDraftsCmd = &cobra.Command{
|
|||
|
||||
for _, p := range sites.Pages() {
|
||||
if p.IsDraft() {
|
||||
fmt.Println(filepath.Join(p.File.Dir(), p.File.LogicalName()))
|
||||
jww.FEEDBACK.Println(filepath.Join(p.File.Dir(), p.File.LogicalName()))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ posted in the future.`,
|
|||
|
||||
for _, p := range sites.Pages() {
|
||||
if p.IsFuture() {
|
||||
fmt.Println(filepath.Join(p.File.Dir(), p.File.LogicalName()))
|
||||
jww.FEEDBACK.Println(filepath.Join(p.File.Dir(), p.File.LogicalName()))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ expired.`,
|
|||
|
||||
for _, p := range sites.Pages() {
|
||||
if p.IsExpired() {
|
||||
fmt.Println(filepath.Join(p.File.Dir(), p.File.LogicalName()))
|
||||
jww.FEEDBACK.Println(filepath.Join(p.File.Dir(), p.File.LogicalName()))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
|
@ -54,9 +54,9 @@ func config(cmd *cobra.Command, args []string) error {
|
|||
for _, k := range keys {
|
||||
kv := reflect.ValueOf(allSettings[k])
|
||||
if kv.Kind() == reflect.String {
|
||||
fmt.Printf("%s%s\"%+v\"\n", k, separator, allSettings[k])
|
||||
jww.FEEDBACK.Printf("%s%s\"%+v\"\n", k, separator, allSettings[k])
|
||||
} else {
|
||||
fmt.Printf("%s%s%+v\n", k, separator, allSettings[k])
|
||||
jww.FEEDBACK.Printf("%s%s%+v\n", k, separator, allSettings[k])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ func serve(port int) {
|
|||
}
|
||||
|
||||
jww.FEEDBACK.Printf("Web Server is available at %s (bind address %s)\n", u.String(), serverInterface)
|
||||
fmt.Println("Press Ctrl+C to stop")
|
||||
jww.FEEDBACK.Println("Press Ctrl+C to stop")
|
||||
|
||||
endpoint := net.JoinHostPort(serverInterface, strconv.Itoa(port))
|
||||
err = http.ListenAndServe(endpoint, nil)
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -24,6 +23,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/hugo/helpers"
|
||||
"github.com/spf13/hugo/hugolib"
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
)
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
|
@ -32,7 +32,6 @@ var versionCmd = &cobra.Command{
|
|||
Long: `All software has versions. This is Hugo's.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
printHugoVersion()
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
@ -44,9 +43,9 @@ func printHugoVersion() {
|
|||
formatBuildDate() // format the compile time
|
||||
}
|
||||
if hugolib.CommitHash == "" {
|
||||
fmt.Printf("Hugo Static Site Generator v%s BuildDate: %s\n", helpers.HugoVersion(), hugolib.BuildDate)
|
||||
jww.FEEDBACK.Printf("Hugo Static Site Generator v%s BuildDate: %s\n", helpers.HugoVersion(), hugolib.BuildDate)
|
||||
} else {
|
||||
fmt.Printf("Hugo Static Site Generator v%s-%s BuildDate: %s\n", helpers.HugoVersion(), strings.ToUpper(hugolib.CommitHash), hugolib.BuildDate)
|
||||
jww.FEEDBACK.Printf("Hugo Static Site Generator v%s-%s BuildDate: %s\n", helpers.HugoVersion(), strings.ToUpper(hugolib.CommitHash), hugolib.BuildDate)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,12 +59,12 @@ func setBuildDate() {
|
|||
fname, _ := osext.Executable()
|
||||
dir, err := filepath.Abs(filepath.Dir(fname))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
jww.ERROR.Println(err)
|
||||
return
|
||||
}
|
||||
fi, err := os.Lstat(filepath.Join(dir, filepath.Base(fname)))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
jww.ERROR.Println(err)
|
||||
return
|
||||
}
|
||||
t := fi.ModTime()
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/PuerkitoBio/purell"
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
|
@ -306,7 +307,7 @@ func URLPrep(ugly bool, in string) string {
|
|||
}
|
||||
url, err := purell.NormalizeURLString(x, purell.FlagAddTrailingSlash)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR returned by NormalizeURLString. Returning in = %q\n", in)
|
||||
jww.ERROR.Printf("Failed to normalize URL string. Returning in = %q\n", in)
|
||||
return in
|
||||
}
|
||||
return url
|
||||
|
|
Loading…
Reference in a new issue