1414package commands
1515
1616import (
17- "os"
18- "path/filepath"
1917 "runtime"
2018 "strings"
21- "time"
2219
2320 "github.com/gohugoio/hugo/helpers"
2421 "github.com/gohugoio/hugo/hugolib"
25- "github.com/kardianos/osext"
2622 "github.com/spf13/cobra"
2723 jww "github.com/spf13/jwalterweatherman"
2824)
@@ -38,43 +34,9 @@ var versionCmd = &cobra.Command{
3834}
3935
4036func printHugoVersion () {
41- if hugolib .BuildDate == "" {
42- setBuildDate () // set the build date from executable's mdate
43- } else {
44- formatBuildDate () // format the compile time
45- }
4637 if hugolib .CommitHash == "" {
4738 jww .FEEDBACK .Printf ("Hugo Static Site Generator v%s %s/%s BuildDate: %s\n " , helpers .CurrentHugoVersion , runtime .GOOS , runtime .GOARCH , hugolib .BuildDate )
4839 } else {
4940 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 )
5041 }
5142}
52-
53- // setBuildDate checks the ModTime of the Hugo executable and returns it as a
54- // formatted string. This assumes that the executable name is Hugo, if it does
55- // not exist, an empty string will be returned. This is only called if the
56- // hugolib.BuildDate wasn't set during compile time.
57- //
58- // osext is used for cross-platform.
59- func setBuildDate () {
60- fname , _ := osext .Executable ()
61- dir , err := filepath .Abs (filepath .Dir (fname ))
62- if err != nil {
63- jww .ERROR .Println (err )
64- return
65- }
66- fi , err := os .Lstat (filepath .Join (dir , filepath .Base (fname )))
67- if err != nil {
68- jww .ERROR .Println (err )
69- return
70- }
71- t := fi .ModTime ()
72- hugolib .BuildDate = t .Format (time .RFC3339 )
73- }
74-
75- // formatBuildDate formats the hugolib.BuildDate according to the value in
76- // .Params.DateFormat, if it's set.
77- func formatBuildDate () {
78- t , _ := time .Parse ("2006-01-02T15:04:05-0700" , hugolib .BuildDate )
79- hugolib .BuildDate = t .Format (time .RFC3339 )
80- }
0 commit comments