github.com/jerryclinesmith/packer@v0.3.7/packer/version.go (about)

     1  package packer
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  )
     7  
     8  // The git commit that is being compiled. This will be filled in by the
     9  // compiler for source builds.
    10  var GitCommit string
    11  
    12  // The version of packer.
    13  const Version = "0.3.7"
    14  
    15  // Any pre-release marker for the version. If this is "" (empty string),
    16  // then it means that it is a final release. Otherwise, this is the
    17  // pre-release marker.
    18  const VersionPrerelease = ""
    19  
    20  type versionCommand byte
    21  
    22  func (versionCommand) Help() string {
    23  	return `usage: packer version
    24  
    25  Outputs the version of Packer that is running. There are no additional
    26  command-line flags for this command.`
    27  }
    28  
    29  func (versionCommand) Run(env Environment, args []string) int {
    30  	env.Ui().Machine("version", Version)
    31  	env.Ui().Machine("version-prelease", VersionPrerelease)
    32  	env.Ui().Machine("version-commit", GitCommit)
    33  
    34  	var versionString bytes.Buffer
    35  	fmt.Fprintf(&versionString, "Packer v%s", Version)
    36  	if VersionPrerelease != "" {
    37  		fmt.Fprintf(&versionString, ".%s", VersionPrerelease)
    38  
    39  		if GitCommit != "" {
    40  			fmt.Fprintf(&versionString, " (%s)", GitCommit)
    41  		}
    42  	}
    43  
    44  	env.Ui().Say(versionString.String())
    45  	return 0
    46  }
    47  
    48  func (versionCommand) Synopsis() string {
    49  	return "print Packer version"
    50  }