github.com/shohhei1126/hugo@v0.42.2-0.20180623210752-3d5928889ad7/commands/version.go (about) 1 // Copyright 2015 The Hugo Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package commands 15 16 import ( 17 "runtime" 18 "strings" 19 20 "github.com/gohugoio/hugo/helpers" 21 "github.com/gohugoio/hugo/hugolib" 22 "github.com/spf13/cobra" 23 jww "github.com/spf13/jwalterweatherman" 24 ) 25 26 var _ cmder = (*versionCmd)(nil) 27 28 type versionCmd struct { 29 *baseCmd 30 } 31 32 func newVersionCmd() *versionCmd { 33 return &versionCmd{ 34 newBaseCmd(&cobra.Command{ 35 Use: "version", 36 Short: "Print the version number of Hugo", 37 Long: `All software has versions. This is Hugo's.`, 38 RunE: func(cmd *cobra.Command, args []string) error { 39 printHugoVersion() 40 return nil 41 }, 42 }), 43 } 44 } 45 46 func printHugoVersion() { 47 if hugolib.CommitHash == "" { 48 if hugolib.BuildDate == "" { 49 jww.FEEDBACK.Printf("Hugo Static Site Generator v%s %s/%s\n", helpers.CurrentHugoVersion, runtime.GOOS, runtime.GOARCH) 50 } else { 51 jww.FEEDBACK.Printf("Hugo Static Site Generator v%s %s/%s BuildDate: %s\n", helpers.CurrentHugoVersion, runtime.GOOS, runtime.GOARCH, hugolib.BuildDate) 52 } 53 } else { 54 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) 55 } 56 }