From e137f4dafd2ef1f02f7cbc6a3429ccf36733e9f9 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Tue, 19 Jul 2016 18:38:15 -0700 Subject: [PATCH] Adds version info back into the config. In #2191 I accedentally broke SCADA by not populating the agent's version information into the config structure. This adds it back, and makes the distinction between the raw parts we send to APIs and the human form of the version that we display. --- command/agent/command.go | 32 ++++++++++++++++++++------------ command/version.go | 6 +++--- commands.go | 13 ++++++++----- version.go | 5 +++-- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/command/agent/command.go b/command/agent/command.go index bb601ccffe..79cccbbcbf 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -38,18 +38,21 @@ var validDatacenter = regexp.MustCompile("^[a-zA-Z0-9_-]+$") // ShutdownCh. If two messages are sent on the ShutdownCh it will forcibly // exit. type Command struct { - Version string - Ui cli.Ui - ShutdownCh <-chan struct{} - args []string - logFilter *logutils.LevelFilter - logOutput io.Writer - agent *Agent - rpcServer *AgentRPC - httpServers []*HTTPServer - dnsServer *DNSServer - scadaProvider *scada.Provider - scadaHttp *HTTPServer + Revision string + Version string + VersionPrerelease string + HumanVersion string + Ui cli.Ui + ShutdownCh <-chan struct{} + args []string + logFilter *logutils.LevelFilter + logOutput io.Writer + agent *Agent + rpcServer *AgentRPC + httpServers []*HTTPServer + dnsServer *DNSServer + scadaProvider *scada.Provider + scadaHttp *HTTPServer } // readConfig is responsible for setup of our configuration using @@ -309,6 +312,11 @@ func (c *Command) readConfig() *Config { c.Ui.Error("WARNING: Bootstrap mode enabled! Do not enable unless necessary") } + // Set the version info + config.Revision = c.Revision + config.Version = c.Version + config.VersionPrerelease = c.VersionPrerelease + return config } diff --git a/command/version.go b/command/version.go index f8b9705422..4e91214b99 100644 --- a/command/version.go +++ b/command/version.go @@ -8,8 +8,8 @@ import ( // VersionCommand is a Command implementation prints the version. type VersionCommand struct { - Version string - Ui cli.Ui + HumanVersion string + Ui cli.Ui } func (c *VersionCommand) Help() string { @@ -17,7 +17,7 @@ func (c *VersionCommand) Help() string { } func (c *VersionCommand) Run(_ []string) int { - c.Ui.Output(fmt.Sprintf("Consul Version: %s", c.Version)) + c.Ui.Output(fmt.Sprintf("Consul Version: %s", c.HumanVersion)) c.Ui.Output(fmt.Sprintf("Supported Protocol Version(s): %d to %d", consul.ProtocolVersionMin, consul.ProtocolVersionMax)) return 0 diff --git a/commands.go b/commands.go index 51d55d8b07..84f0c07fe6 100644 --- a/commands.go +++ b/commands.go @@ -19,9 +19,12 @@ func init() { Commands = map[string]cli.CommandFactory{ "agent": func() (cli.Command, error) { return &agent.Command{ - Version: GetVersion(), - Ui: ui, - ShutdownCh: make(chan struct{}), + Revision: GitCommit, + Version: Version, + VersionPrerelease: VersionPrerelease, + HumanVersion: GetHumanVersion(), + Ui: ui, + ShutdownCh: make(chan struct{}), }, nil }, @@ -120,8 +123,8 @@ func init() { "version": func() (cli.Command, error) { return &command.VersionCommand{ - Version: GetVersion(), - Ui: ui, + HumanVersion: GetHumanVersion(), + Ui: ui, }, nil }, diff --git a/version.go b/version.go index cfb39c84a7..e158f79dc1 100644 --- a/version.go +++ b/version.go @@ -19,8 +19,9 @@ const Version = "0.7.0" // such as "dev" (in development), "beta", "rc1", etc. const VersionPrerelease = "dev" -// GetVersion returns the full version of Consul. -func GetVersion() string { +// GetHumanVersion composes the parts of the version in a way that's suitable +// for displaying to humans. +func GetHumanVersion() string { version := Version if GitDescribe != "" { version = GitDescribe