Print version on startup.

Fixes #765
This commit is contained in:
Jeff Mitchell 2015-11-09 13:52:55 -05:00
parent 3717b31b63
commit 75f1c1e40c
8 changed files with 72 additions and 46 deletions

View File

@ -33,6 +33,7 @@ IMPROVEMENTS:
* core: Tokens can now renew themselves [GH-455]
* core: Base64-encoded PGP keys can be used with the CLI for `init` and
`rekey` operations [GH-653]
* core: Print version on startup [GH-765]
* credential/token: Display whether or not a token is an orphan in the output
of a lookup call [GH-766]
* logical: Allow `.` in path-based variables in many more locations [GH-244]

View File

@ -7,6 +7,7 @@ import (
auditFile "github.com/hashicorp/vault/builtin/audit/file"
auditSyslog "github.com/hashicorp/vault/builtin/audit/syslog"
"github.com/hashicorp/vault/version"
credAppId "github.com/hashicorp/vault/builtin/credential/app-id"
credCert "github.com/hashicorp/vault/builtin/credential/cert"
@ -267,20 +268,11 @@ func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory {
},
"version": func() (cli.Command, error) {
ver := Version
rel := VersionPrerelease
if GitDescribe != "" {
ver = GitDescribe
}
if GitDescribe == "" && rel == "" && VersionPrerelease != "" {
rel = "dev"
}
versionInfo := version.GetVersion()
return &command.VersionCommand{
Revision: GitCommit,
Version: ver,
VersionPrerelease: rel,
Ui: meta.Ui,
VersionInfo: versionInfo,
Ui: meta.Ui,
}, nil
},

View File

@ -1,13 +0,0 @@
package cli
// The git commit that was compiled. This will be filled in by the compiler.
var GitCommit string
var GitDescribe string
// The main version number that is being run at the moment.
const Version = "0.3.1"
// A pre-release marker for the version. If this is "" (empty string)
// then it means that it is a final release. Otherwise, this is a pre-release
// such as "dev" (in development), "beta", "rc1", etc.
const VersionPrerelease = "dev"

View File

@ -25,6 +25,7 @@ import (
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/physical"
"github.com/hashicorp/vault/vault"
"github.com/hashicorp/vault/version"
)
// ServerCommand is a Command that starts the Vault server.
@ -231,6 +232,9 @@ func (c *ServerCommand) Run(args []string) int {
go server.Serve(ln)
}
infoKeys = append(infoKeys, "version")
info["version"] = version.GetVersion().String()
// Server configuration output
padding := 18
c.Ui.Output("==> Vault server configuration:\n")

View File

@ -1,18 +1,14 @@
package command
import (
"bytes"
"fmt"
"github.com/hashicorp/vault/version"
"github.com/mitchellh/cli"
)
// VersionCommand is a Command implementation prints the version.
type VersionCommand struct {
Revision string
Version string
VersionPrerelease string
Ui cli.Ui
VersionInfo *version.VersionInfo
Ui cli.Ui
}
func (c *VersionCommand) Help() string {
@ -20,18 +16,7 @@ func (c *VersionCommand) Help() string {
}
func (c *VersionCommand) Run(_ []string) int {
var versionString bytes.Buffer
fmt.Fprintf(&versionString, "Vault v%s", c.Version)
if c.VersionPrerelease != "" {
fmt.Fprintf(&versionString, "-%s", c.VersionPrerelease)
if c.Revision != "" {
fmt.Fprintf(&versionString, " (%s)", c.Revision)
}
}
c.Ui.Output(versionString.String())
c.Ui.Output(c.VersionInfo.String())
return 0
}

View File

@ -47,7 +47,7 @@ gox \
-os="!freebsd" \
-os="!openbsd" \
-arch="${XC_ARCH}" \
-ldflags "-X github.com/hashicorp/vault/cli.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \
-ldflags "-X github.com/hashicorp/vault/version.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \
-output "pkg/{{.OS}}_{{.Arch}}/vault" \
.

View File

@ -67,7 +67,7 @@ echo ==^> Building...
gox^
-os="%_XC_OS%"^
-arch="%_XC_ARCH%"^
-ldflags "-X github.com/hashicorp/vault/cli.GitCommit %_GIT_COMMIT%%_GIT_DIRTY%"^
-ldflags "-X github.com/hashicorp/vault/version.GitCommit %_GIT_COMMIT%%_GIT_DIRTY%"^
-output "pkg/{{.OS}}_{{.Arch}}/vault"^
.

57
version/version.go Normal file
View File

@ -0,0 +1,57 @@
package version
import (
"bytes"
"fmt"
)
// The git commit that was compiled. This will be filled in by the compiler.
var GitCommit string
var GitDescribe string
// The main version number that is being run at the moment.
const Version = "0.3.1"
// A pre-release marker for the version. If this is "" (empty string)
// then it means that it is a final release. Otherwise, this is a pre-release
// such as "dev" (in development), "beta", "rc1", etc.
const VersionPrerelease = "dev"
// VersionInfo
type VersionInfo struct {
Revision string
Version string
VersionPrerelease string
}
func GetVersion() *VersionInfo {
ver := Version
rel := VersionPrerelease
if GitDescribe != "" {
ver = GitDescribe
}
if GitDescribe == "" && rel == "" && VersionPrerelease != "" {
rel = "dev"
}
return &VersionInfo{
Revision: GitCommit,
Version: ver,
VersionPrerelease: rel,
}
}
func (c *VersionInfo) String() string {
var versionString bytes.Buffer
fmt.Fprintf(&versionString, "Vault v%s", c.Version)
if c.VersionPrerelease != "" {
fmt.Fprintf(&versionString, "-%s", c.VersionPrerelease)
if c.Revision != "" {
fmt.Fprintf(&versionString, " (%s)", c.Revision)
}
}
return versionString.String()
}