shithub: hugo

Download patch

ref: 120f6b0cf20dfc977f33e650530d866e28e52a28
parent: e1da7cb3204c6d232f4a1bdbf89ce75d8459a8b8
author: bogem <albertnigma@gmail.com>
date: Tue Nov 22 13:47:20 EST 2016

all: Use jww instead of fmt for printing

This is an attempt to unify method for printing.

--- a/commands/env.go
+++ b/commands/env.go
@@ -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 @@
 	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
 	},
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -415,7 +415,7 @@
 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 @@
 		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 @@
 		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 @@
 		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 @@
 
 					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 @@
 							// 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 @@
 				}
 
 				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 @@
 				}
 			case err := <-watcher.Errors:
 				if err != nil {
-					fmt.Println("error:", err)
+					jww.ERROR.Println(err)
 				}
 			}
 		}
--- a/commands/import_jekyll.go
+++ b/commands/import_jekyll.go
@@ -16,7 +16,6 @@
 import (
 	"bytes"
 	"errors"
-	"fmt"
 	"io"
 	"io/ioutil"
 	"os"
@@ -90,7 +89,7 @@
 		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 @@
 	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
 }
--- a/commands/list.go
+++ b/commands/list.go
@@ -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 @@
 
 		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 @@
 
 		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 @@
 
 		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()))
 			}
 
 		}
--- a/commands/list_config.go
+++ b/commands/list_config.go
@@ -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 @@
 	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])
 		}
 	}
 
--- a/commands/server.go
+++ b/commands/server.go
@@ -211,7 +211,7 @@
 	}
 
 	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)
--- a/commands/version.go
+++ b/commands/version.go
@@ -14,7 +14,6 @@
 package commands
 
 import (
-	"fmt"
 	"os"
 	"path/filepath"
 	"strings"
@@ -24,6 +23,7 @@
 	"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 @@
 	Long:  `All software has versions. This is Hugo's.`,
 	RunE: func(cmd *cobra.Command, args []string) error {
 		printHugoVersion()
-
 		return nil
 	},
 }
@@ -44,9 +43,9 @@
 		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 @@
 	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()
--- a/helpers/url.go
+++ b/helpers/url.go
@@ -20,6 +20,7 @@
 	"strings"
 
 	"github.com/PuerkitoBio/purell"
+	jww "github.com/spf13/jwalterweatherman"
 	"github.com/spf13/viper"
 )
 
@@ -306,7 +307,7 @@
 	}
 	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
--