2013-03-24 14:03:53 -07:00
|
|
|
package packer
|
|
|
|
|
2013-06-19 22:20:52 -07:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
)
|
2013-05-27 15:12:48 -07:00
|
|
|
|
2013-07-08 15:37:01 -07:00
|
|
|
// The git commit that is being compiled. This will be filled in by the
|
|
|
|
// compiler for source builds.
|
|
|
|
var GitCommit string
|
|
|
|
|
2013-03-24 14:03:53 -07:00
|
|
|
// The version of packer.
|
2014-04-28 15:03:09 -07:00
|
|
|
const Version = "0.6.0"
|
2013-06-19 22:20:52 -07:00
|
|
|
|
|
|
|
// 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 20:53:56 -08:00
|
|
|
const VersionPrerelease = "dev"
|
2013-03-24 14:03:53 -07:00
|
|
|
|
|
|
|
type versionCommand byte
|
|
|
|
|
2013-06-02 11:41:12 -07:00
|
|
|
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 14:03:55 -07:00
|
|
|
func (versionCommand) Run(env Environment, args []string) int {
|
2013-08-11 23:56:47 -07:00
|
|
|
env.Ui().Machine("version", Version)
|
|
|
|
env.Ui().Machine("version-prelease", VersionPrerelease)
|
|
|
|
env.Ui().Machine("version-commit", GitCommit)
|
|
|
|
|
2014-01-09 13:20:30 -08:00
|
|
|
env.Ui().Say(VersionString())
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (versionCommand) Synopsis() string {
|
|
|
|
return "print Packer version"
|
|
|
|
}
|
|
|
|
|
2014-01-19 15:48:56 -08:00
|
|
|
// VersionString returns the Packer version in human-readable
|
|
|
|
// form complete with pre-release and git commit info if it is
|
|
|
|
// available.
|
2014-01-09 13:20:30 -08:00
|
|
|
func VersionString() string {
|
2013-06-19 22:20:52 -07:00
|
|
|
var versionString bytes.Buffer
|
|
|
|
fmt.Fprintf(&versionString, "Packer v%s", Version)
|
|
|
|
if VersionPrerelease != "" {
|
|
|
|
fmt.Fprintf(&versionString, ".%s", VersionPrerelease)
|
|
|
|
|
2013-07-08 15:38:14 -07:00
|
|
|
if GitCommit != "" {
|
|
|
|
fmt.Fprintf(&versionString, " (%s)", GitCommit)
|
|
|
|
}
|
2013-07-08 15:37:01 -07:00
|
|
|
}
|
|
|
|
|
2014-01-19 19:30:11 -08:00
|
|
|
return versionString.String()
|
2013-03-24 16:28:35 -07:00
|
|
|
}
|