Re-factor version command to use version.FormattedVersion() function.
This commit removes surplus code which is almost a duplicate of the code available in the version package by favouring the package implementation instead. Signed-off-by: Krzysztof Wilczynski <kw@linux.com>
This commit is contained in:
parent
8a30b3db80
commit
0e08640fff
@ -1,18 +1,16 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/hashicorp/packer/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// VersionCommand is a Command implementation prints the version.
|
// VersionCommand is a Command implementation prints the version.
|
||||||
type VersionCommand struct {
|
type VersionCommand struct {
|
||||||
Meta
|
Meta
|
||||||
|
|
||||||
Revision string
|
CheckFunc VersionCheckFunc
|
||||||
Version string
|
|
||||||
VersionPrerelease string
|
|
||||||
CheckFunc VersionCheckFunc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// VersionCheckFunc is the callback called by the Version command to
|
// VersionCheckFunc is the callback called by the Version command to
|
||||||
@ -29,25 +27,15 @@ type VersionCheckInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *VersionCommand) Help() string {
|
func (c *VersionCommand) Help() string {
|
||||||
return ""
|
return "Prints the Packer version, and checks for new release."
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *VersionCommand) Run(args []string) int {
|
func (c *VersionCommand) Run(args []string) int {
|
||||||
c.Ui.Machine("version", c.Version)
|
c.Ui.Machine("version", version.Version)
|
||||||
c.Ui.Machine("version-prelease", c.VersionPrerelease)
|
c.Ui.Machine("version-prelease", version.VersionPrerelease)
|
||||||
c.Ui.Machine("version-commit", c.Revision)
|
c.Ui.Machine("version-commit", version.GitCommit)
|
||||||
|
|
||||||
var versionString bytes.Buffer
|
c.Ui.Say(fmt.Sprintf("Packer v%s", version.FormattedVersion()))
|
||||||
fmt.Fprintf(&versionString, "Packer v%s", c.Version)
|
|
||||||
if c.VersionPrerelease != "" {
|
|
||||||
fmt.Fprintf(&versionString, "-%s", c.VersionPrerelease)
|
|
||||||
|
|
||||||
if c.Revision != "" {
|
|
||||||
fmt.Fprintf(&versionString, " (%s)", c.Revision)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Ui.Say(versionString.String())
|
|
||||||
|
|
||||||
// If we have a version check function, then let's check for
|
// If we have a version check function, then let's check for
|
||||||
// the latest version as well.
|
// the latest version as well.
|
||||||
|
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hashicorp/packer/command"
|
"github.com/hashicorp/packer/command"
|
||||||
"github.com/hashicorp/packer/version"
|
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -50,11 +49,8 @@ func init() {
|
|||||||
|
|
||||||
"version": func() (cli.Command, error) {
|
"version": func() (cli.Command, error) {
|
||||||
return &command.VersionCommand{
|
return &command.VersionCommand{
|
||||||
Meta: *CommandMeta,
|
Meta: *CommandMeta,
|
||||||
Revision: version.GitCommit,
|
CheckFunc: commandVersionCheck,
|
||||||
Version: version.Version,
|
|
||||||
VersionPrerelease: version.VersionPrerelease,
|
|
||||||
CheckFunc: commandVersionCheck,
|
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user