Clean up server & build site logic. Fixed #94 - hugo - [fork] hugo port for 9front
 (HTM) git clone git@git.drkhsh.at/hugo.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 0318f7c149f98eb2bcbb44b0ca1c7420379190eb
 (DIR) parent e6ace71fecd075b96aa81b8daa3f3c368f27325f
 (HTM) Author: spf13 <steve.francia@gmail.com>
       Date:   Wed,  9 Oct 2013 18:52:29 -0400
       
       Clean up server & build site logic. Fixed #94
       
       Diffstat:
         M commands/hugo.go                    |      31 +++++++++++--------------------
         M commands/server.go                  |       2 +-
         A utils/utils.go                      |      22 ++++++++++++++++++++++
       
       3 files changed, 34 insertions(+), 21 deletions(-)
       ---
 (DIR) diff --git a/commands/hugo.go b/commands/hugo.go
       @@ -19,8 +19,8 @@ import (
                "github.com/mostafah/fsync"
                "github.com/spf13/cobra"
                "github.com/spf13/hugo/hugolib"
       +        "github.com/spf13/hugo/utils"
                "github.com/spf13/nitro"
       -        "log"
                "os"
                "path/filepath"
                "strings"
       @@ -36,7 +36,10 @@ var HugoCmd = &cobra.Command{
        love by spf13 and friends in Go.
        
        Complete documentation is available at http://hugo.spf13.com`,
       -        Run: build,
       +        Run: func(cmd *cobra.Command, args []string) {
       +                InitializeConfig()
       +                build()
       +        },
        }
        
        var Hugo *cobra.Commander
       @@ -46,10 +49,7 @@ var Source, Destination, BaseUrl, CfgFile string
        func Execute() {
                AddCommands()
                Hugo := HugoCmd.ToCommander()
       -        err := Hugo.Execute()
       -        if err != nil {
       -                os.Exit(-1)
       -        }
       +        utils.CheckErrExit(Hugo.Execute())
        }
        
        func AddCommands() {
       @@ -84,25 +84,16 @@ func InitializeConfig() {
                }
        }
        
       -func build(cmd *cobra.Command, args []string) {
       -        InitializeConfig()
       +func build() {
       +        utils.CheckErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", Config.GetAbsPath(Config.PublishDir)))
        
       -        err := copyStatic()
       -        if err != nil {
       -                log.Fatalf("Error copying static files to %s: %v", Config.GetAbsPath(Config.PublishDir), err)
       -        }
       -        if _, err := buildSite(); err != nil {
       -                fmt.Println(err)
       -                os.Exit(-1)
       -        }
       +        _, e := buildSite()
       +        utils.CheckErrExit(e)
        
                if BuildWatch {
                        fmt.Println("Watching for changes in", Config.GetAbsPath(Config.ContentDir))
                        fmt.Println("Press ctrl+c to stop")
       -                err := NewWatcher(0)
       -                if err != nil {
       -                        fmt.Println(err)
       -                }
       +                utils.CheckErr(NewWatcher(0))
                }
        }
        
 (DIR) diff --git a/commands/server.go b/commands/server.go
       @@ -45,7 +45,7 @@ func server(cmd *cobra.Command, args []string) {
                        Config.BaseUrl = "http://localhost:" + strconv.Itoa(serverPort)
                }
        
       -        build(cmd, args)
       +        build()
        
                // Watch runs its own server as part of the routine
                if serverWatch {
 (DIR) diff --git a/utils/utils.go b/utils/utils.go
       @@ -0,0 +1,22 @@
       +package utils
       +
       +import (
       +        "log"
       +        "os"
       +)
       +
       +func CheckErr(err error, s ...string) {
       +        if err != nil {
       +                for _, message := range s {
       +                        log.Fatalf(message)
       +                }
       +                log.Fatalf("Fatal Error: %v", err)
       +        }
       +}
       +
       +func CheckErrExit(err error, s ...string) {
       +        if err != nil {
       +                CheckErr(err, s...)
       +                os.Exit(-1)
       +        }
       +}