Skip to content

Commit

Permalink
Print version on startup.
Browse files Browse the repository at this point in the history
Fixes #765
  • Loading branch information
jefferai committed Nov 9, 2015
1 parent ee31463 commit 904e1ee
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
16 changes: 4 additions & 12 deletions cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
},

Expand Down
13 changes: 0 additions & 13 deletions cli/version.go

This file was deleted.

4 changes: 4 additions & 0 deletions command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down
23 changes: 4 additions & 19 deletions command/version.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
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 {
return ""
}

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
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
.

Expand Down
2 changes: 1 addition & 1 deletion scripts/windows/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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"^
.

Expand Down
57 changes: 57 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 904e1ee

Please sign in to comment.