Permalink
Browse files

commands: Remove superflous BuildDate logic

Fixes #4272
  • Loading branch information...
bep committed Jan 14, 2018
1 parent 51dd462 commit 13d53b31f19240879122d6b7e4aaeb60b5130a3c
Showing with 1 addition and 49 deletions.
  1. +1 −7 Gopkg.lock
  2. +0 −4 Gopkg.toml
  3. +0 −38 commands/version.go

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -52,10 +52,6 @@
name = "github.com/jdkato/prose"
version = "1.1.0"
[[constraint]]
branch = "master"
name = "github.com/kardianos/osext"
[[constraint]]
name = "github.com/kyokomi/emoji"
version = "1.5.0"
@@ -14,15 +14,11 @@
package commands
import (
"os"
"path/filepath"
"runtime"
"strings"
"time"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugolib"
"github.com/kardianos/osext"
"github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman"
)
@@ -38,43 +34,9 @@ var versionCmd = &cobra.Command{
}
func printHugoVersion() {
if hugolib.BuildDate == "" {
setBuildDate() // set the build date from executable's mdate
} else {
formatBuildDate() // format the compile time
}
if hugolib.CommitHash == "" {
jww.FEEDBACK.Printf("Hugo Static Site Generator v%s %s/%s BuildDate: %s\n", helpers.CurrentHugoVersion, runtime.GOOS, runtime.GOARCH, hugolib.BuildDate)
} else {
jww.FEEDBACK.Printf("Hugo Static Site Generator v%s-%s %s/%s BuildDate: %s\n", helpers.CurrentHugoVersion, strings.ToUpper(hugolib.CommitHash), runtime.GOOS, runtime.GOARCH, hugolib.BuildDate)
}
}
// setBuildDate checks the ModTime of the Hugo executable and returns it as a
// formatted string. This assumes that the executable name is Hugo, if it does
// not exist, an empty string will be returned. This is only called if the
// hugolib.BuildDate wasn't set during compile time.
//
// osext is used for cross-platform.
func setBuildDate() {
fname, _ := osext.Executable()
dir, err := filepath.Abs(filepath.Dir(fname))
if err != nil {
jww.ERROR.Println(err)
return
}
fi, err := os.Lstat(filepath.Join(dir, filepath.Base(fname)))
if err != nil {
jww.ERROR.Println(err)
return
}
t := fi.ModTime()
hugolib.BuildDate = t.Format(time.RFC3339)
}
// formatBuildDate formats the hugolib.BuildDate according to the value in
// .Params.DateFormat, if it's set.
func formatBuildDate() {
t, _ := time.Parse("2006-01-02T15:04:05-0700", hugolib.BuildDate)
hugolib.BuildDate = t.Format(time.RFC3339)
}

0 comments on commit 13d53b3

Please sign in to comment.