diff --git a/cli.go b/cli.go index 0091293..10949bd 100644 --- a/cli.go +++ b/cli.go @@ -32,7 +32,7 @@ func RunCustom(args []string, commands map[string]cli.CommandFactory) int { // just show the version. for _, arg := range args { if arg == "-v" || arg == "-version" || arg == "--version" { - newArgs := make([]string, len(args)+1) + newArgs := make([]string, len(args) + 1) newArgs[0] = "version" copy(newArgs[1:], args) args = newArgs diff --git a/command/version.go b/command/version.go index 666c97c..7cee806 100644 --- a/command/version.go +++ b/command/version.go @@ -8,17 +8,25 @@ import ( type VersionCommand struct { Meta - Name string - Version string - Revision string + Name string + Revision string + Version string + BuildBy string + Tag string } func (c *VersionCommand) Run(args []string) int { var versionString bytes.Buffer - fmt.Fprintf(&versionString, "%s version %s", c.Name, c.Version) + fmt.Fprintf(&versionString, "%s version ", c.Name, c.Version) if c.Revision != "" { - fmt.Fprintf(&versionString, " (%s)", c.Revision) + fmt.Fprintf(&versionString, " Revision : %s", c.Revision) + } + if c.BuildBy != "" { + fmt.Fprintf(&versionString, " Build by : %s", c.BuildBy) + } + if c.Tag != "" { + fmt.Fprintf(&versionString, " Tag : %s", c.Tag) } c.Ui.Output(versionString.String()) @@ -28,7 +36,6 @@ func (c *VersionCommand) Run(args []string) int { func (c *VersionCommand) Synopsis() string { return fmt.Sprintf("Print %s version and quit", c.Name) } - func (c *VersionCommand) Help() string { return "" } diff --git a/commands.go b/commands.go index 2f08560..5488390 100644 --- a/commands.go +++ b/commands.go @@ -36,9 +36,12 @@ func Commands(meta *command.Meta) map[string]cli.CommandFactory { "version": func() (cli.Command, error) { return &command.VersionCommand{ Meta: *meta, - Version: Version, - Revision: GitCommit, Name: Name, + Revision: GitCommit, + Version: Version, + BuildBy: BuiltUser, + Tag: GitTag, + }, nil }, } diff --git a/version.go b/version.go index d1b54fd..b7bfa12 100644 --- a/version.go +++ b/version.go @@ -7,3 +7,5 @@ const Version string = "0.1.0" // This value is extracted by git command when building. // To set this from outside, use go build -ldflags "-X main.GitCommit \"$(COMMIT)\"" var GitCommit string +var BuiltUser string +var GitTag string