all: Use jww instead of fmt for printing
authorbogem <albertnigma@gmail.com>
Tue, 22 Nov 2016 17:47:20 +0000 (18:47 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 22 Nov 2016 21:06:48 +0000 (22:06 +0100)
This is an attempt to unify method for printing.

commands/env.go
commands/hugo.go
commands/import_jekyll.go
commands/list.go
commands/list_config.go
commands/server.go
commands/version.go
helpers/url.go

index b6ba3dffb8bf35d380b27bcda3de08d5ad348b48..54c98d527bcb6af00114221cc6d79f4dce00af68 100644 (file)
 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
        },
index b6603c6f2f14894b3fe80c3719d9dd21cbedb278..5067083908a7a93626bc966e3a2e52d777e56dfa 100644 (file)
@@ -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)
                                }
                        }
                }
index 8e74fa8d11aeb19960c8b6b607c30cb7fd05fbc5..61b4660e9c2c9e268ff6e988e312486a8ce28609 100644 (file)
@@ -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
 }
index fdf72a67ed5fb85a6c222605192dec73eb8e3677..7a1fbd55c985cf273ddd39fadff3869db9de738b 100644 (file)
 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()))
                        }
 
                }
index d53cc5884d39c42704174ec5ac572fea3e4ea24e..69822f38c2f42dff3530e6a4ba22c90e7c60a7e9 100644 (file)
 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])
                }
        }
 
index f90278ce85e0e1025e1b373cbb91553fb505e2c3..2a7230b52d276e228dd960255bcf0db9be7a91ef 100644 (file)
@@ -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)
index d64a6cf6f16858af6e1561ff3431377a84a81bd8..348464227ed11ff97d2ea894f9421e854b42e302 100644 (file)
@@ -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()
index 922d4aa80e88393db3d53941dc212350c9273b8b..c7697b09251cdcf084ef6c8a4c2abf6183d25103 100644 (file)
@@ -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