From 1521fed1edb7d0c9aec11ec5a000e156f1f586fa Mon Sep 17 00:00:00 2001 From: Jean-Laurent de Morlhon Date: Thu, 19 Nov 2015 12:16:06 +0100 Subject: [PATCH] Add a version command Signed-off-by: Jean-Laurent de Morlhon --- cli/help.go | 4 ++-- cmd/machine.go | 2 +- commands/commands.go | 11 +++++++++++ commands/version.go | 6 ++++++ version/version.go | 7 +++++++ 5 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 commands/version.go diff --git a/cli/help.go b/cli/help.go index a246f63ac4..f52e00e764 100644 --- a/cli/help.go +++ b/cli/help.go @@ -71,7 +71,7 @@ OPTIONS: var helpCommand = Command{ Name: "help", Aliases: []string{"h"}, - Usage: "Shows a list of commands or help for one command", + Usage: "Show a list of commands or help for one command", ArgsUsage: "[command]", Action: func(c *Context) { args := c.Args() @@ -86,7 +86,7 @@ var helpCommand = Command{ var helpSubcommand = Command{ Name: "help", Aliases: []string{"h"}, - Usage: "Shows a list of commands or help for one command", + Usage: "Show a list of commands or help for one command", ArgsUsage: "[command]", Action: func(c *Context) { args := c.Args() diff --git a/cmd/machine.go b/cmd/machine.go index 215b5fc370..c272f6d653 100644 --- a/cmd/machine.go +++ b/cmd/machine.go @@ -88,7 +88,7 @@ func main() { app.Commands = commands.Commands app.CommandNotFound = cmdNotFound app.Usage = "Create and manage machines running Docker." - app.Version = version.Version + " (" + version.GitCommit + ")" + app.Version = version.FullVersion() log.Debug("Docker Machine Version: ", app.Version) diff --git a/commands/commands.go b/commands/commands.go index 4ddffc71a5..d58b2cea54 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -29,6 +29,8 @@ var ( type CommandLine interface { ShowHelp() + ShowVersion() + Application() *cli.App Args() cli.Args @@ -54,6 +56,10 @@ func (c *contextCommandLine) ShowHelp() { cli.ShowCommandHelp(c.Context, c.Command.Name) } +func (c *contextCommandLine) ShowVersion() { + cli.ShowVersion(c.Context) +} + func (c *contextCommandLine) Application() *cli.App { return c.App } @@ -347,6 +353,11 @@ var Commands = []cli.Command{ Description: "Argument is a machine name.", Action: fatalOnError(cmdURL), }, + { + Name: "version", + Usage: "Show the Docker Machine version information", + Action: fatalOnError(cmdVersion), + }, } func printIP(h *host.Host) func() error { diff --git a/commands/version.go b/commands/version.go new file mode 100644 index 0000000000..dbc4a9d7e5 --- /dev/null +++ b/commands/version.go @@ -0,0 +1,6 @@ +package commands + +func cmdVersion(c CommandLine) error { + c.ShowVersion() + return nil +} diff --git a/version/version.go b/version/version.go index 88cee5c081..4b568fcabc 100644 --- a/version/version.go +++ b/version/version.go @@ -1,5 +1,7 @@ package version +import "fmt" + var ( // Version should be updated by hand at each release Version = "0.5.2-dev" @@ -7,3 +9,8 @@ var ( // GitCommit will be overwritten automatically by the build system GitCommit = "HEAD" ) + +// FullVersion formats the version to be printed +func FullVersion() string { + return fmt.Sprintf("%s ( %s )", Version, GitCommit) +}