summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbep <bjorn.erik.pedersen@gmail.com>2015-03-18 12:23:13 +0100
committerbep <bjorn.erik.pedersen@gmail.com>2015-03-18 12:23:13 +0100
commit3273fce044f06f90ae296f9b42431958d2b06e7f (patch)
tree4556f7b1c7ffa73d53d3d5d08214999c095868c7
parent49f20bbc9bf4eb9ecedfa0fd9dde484256ae91d1 (diff)
Refactor Hugo version
Put version handling into the helpers package so it can be used by many, and split version and suffix to make it possible to calculate the next Hugo version.
-rw-r--r--commands/version.go5
-rw-r--r--helpers/hugo.go46
-rw-r--r--helpers/hugo_test.go11
-rw-r--r--hugolib/hugo.go8
4 files changed, 64 insertions, 6 deletions
diff --git a/commands/version.go b/commands/version.go
index 88ea941f7..24a900cad 100644
--- a/commands/version.go
+++ b/commands/version.go
@@ -22,6 +22,7 @@ import (
"github.com/kardianos/osext"
"github.com/spf13/cobra"
+ "github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/hugolib"
)
@@ -38,9 +39,9 @@ var version = &cobra.Command{
formatBuildDate() // format the compile time
}
if hugolib.CommitHash == "" {
- fmt.Printf("Hugo Static Site Generator v%s BuildDate: %s\n", hugolib.Version, hugolib.BuildDate)
+ fmt.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", hugolib.Version, strings.ToUpper(hugolib.CommitHash), hugolib.BuildDate)
+ fmt.Printf("Hugo Static Site Generator v%s-%s BuildDate: %s\n", helpers.HugoVersion(), strings.ToUpper(hugolib.CommitHash), hugolib.BuildDate)
}
},
}
diff --git a/helpers/hugo.go b/helpers/hugo.go
new file mode 100644
index 000000000..ab840a2d7
--- /dev/null
+++ b/helpers/hugo.go
@@ -0,0 +1,46 @@
+// Copyright © 2015 Steve Francia <spf@spf13.com>.
+//
+// Licensed under the Simple Public License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://opensource.org/licenses/Simple-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package helpers
+
+import (
+ "fmt"
+)
+
+// this should be the only one
+const hugoVersionMain = 0.14
+const hugoVersionSuffix = "-DEV" // blank this when doing a release
+
+// HugoVersion returns the current Hugo version. It will include
+// a suffix, typically '-DEV', if it's development version.
+func HugoVersion() string {
+ return hugoVersion(hugoVersionMain, hugoVersionSuffix)
+}
+
+// HugoReleaseVersion is same as HugoVersion, but no suffix.
+func HugoReleaseVersion() string {
+ return hugoVersionNoSuffix(hugoVersionMain)
+}
+
+// NextHugoReleaseVersion returns the next Hugo release version.
+func NextHugoReleaseVersion() string {
+ return hugoVersionNoSuffix(hugoVersionMain + 0.01)
+}
+
+func hugoVersion(version float32, suffix string) string {
+ return fmt.Sprintf("%.2g%s", version, suffix)
+}
+
+func hugoVersionNoSuffix(version float32) string {
+ return fmt.Sprintf("%.2g", version)
+}
diff --git a/helpers/hugo_test.go b/helpers/hugo_test.go
new file mode 100644
index 000000000..90b63d403
--- /dev/null
+++ b/helpers/hugo_test.go
@@ -0,0 +1,11 @@
+package helpers
+
+import (
+ "github.com/stretchr/testify/assert"
+ "testing"
+)
+
+func TestHugoVersion(t *testing.T) {
+ assert.Equal(t, "0.15-DEV", hugoVersion(0.15, "-DEV"))
+ assert.Equal(t, "0.17", hugoVersionNoSuffix(0.16+0.01))
+}
diff --git a/hugolib/hugo.go b/hugolib/hugo.go
index 17ca1c237..da08b93b9 100644
--- a/hugolib/hugo.go
+++ b/hugolib/hugo.go
@@ -1,11 +1,11 @@
package hugolib
import (
+ "fmt"
+ "github.com/spf13/hugo/helpers"
"html/template"
)
-const Version = "0.14-DEV"
-
var (
CommitHash string
BuildDate string
@@ -23,9 +23,9 @@ type HugoInfo struct {
func init() {
hugoInfo = &HugoInfo{
- Version: Version,
+ Version: helpers.HugoVersion(),
CommitHash: CommitHash,
BuildDate: BuildDate,
- Generator: `<meta name="generator" content="Hugo ` + Version + `" />`,
+ Generator: template.HTML(fmt.Sprintf(`<meta name="generator" content="Hugo %s" />`, helpers.HugoVersion())),
}
}