packer-cn/packer/version.go

58 lines
1.4 KiB
Go
Raw Normal View History

package packer
import (
"bytes"
"fmt"
)
2013-07-08 18:37:01 -04:00
// The git commit that is being compiled. This will be filled in by the
// compiler for source builds.
var GitCommit string
// The version of packer.
2014-02-21 23:53:56 -05:00
const Version = "0.5.3"
// Any pre-release marker for the version. If this is "" (empty string),
// then it means that it is a final release. Otherwise, this is the
// pre-release marker.
2014-02-21 23:53:56 -05:00
const VersionPrerelease = "dev"
type versionCommand byte
func (versionCommand) Help() string {
return `usage: packer version
Outputs the version of Packer that is running. There are no additional
command-line flags for this command.`
}
2013-05-02 17:03:55 -04:00
func (versionCommand) Run(env Environment, args []string) int {
env.Ui().Machine("version", Version)
env.Ui().Machine("version-prelease", VersionPrerelease)
env.Ui().Machine("version-commit", GitCommit)
env.Ui().Say(VersionString())
return 0
}
func (versionCommand) Synopsis() string {
return "print Packer version"
}
2014-01-19 18:48:56 -05:00
// VersionString returns the Packer version in human-readable
// form complete with pre-release and git commit info if it is
// available.
func VersionString() string {
var versionString bytes.Buffer
fmt.Fprintf(&versionString, "Packer v%s", Version)
if VersionPrerelease != "" {
fmt.Fprintf(&versionString, ".%s", VersionPrerelease)
if GitCommit != "" {
fmt.Fprintf(&versionString, " (%s)", GitCommit)
}
2013-07-08 18:37:01 -04:00
}
2014-01-19 22:30:11 -05:00
return versionString.String()
2013-03-24 19:28:35 -04:00
}