From 0c74867ee99d74c724b1c47d4f05f946dc079446 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 26 Mar 2020 15:35:34 -0400 Subject: [PATCH] cli: slightly more direct way of printing custom version --- main.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 3744c0e21..93162e0e6 100644 --- a/main.go +++ b/main.go @@ -7,8 +7,10 @@ import ( "os" "github.com/hashicorp/consul/command" + "github.com/hashicorp/consul/command/version" "github.com/hashicorp/consul/lib" _ "github.com/hashicorp/consul/service_os" + consulversion "github.com/hashicorp/consul/version" "github.com/mitchellh/cli" ) @@ -23,18 +25,6 @@ func main() { func realMain() int { log.SetOutput(ioutil.Discard) - args := os.Args[1:] - for _, arg := range args { - if arg == "--" { - break - } - - if arg == "-v" || arg == "--version" { - args = []string{"version"} - break - } - } - ui := &cli.BasicUi{Writer: os.Stdout, ErrorWriter: os.Stderr} cmds := command.Map(ui) var names []string @@ -43,7 +33,7 @@ func realMain() int { } cli := &cli.CLI{ - Args: args, + Args: os.Args[1:], Commands: cmds, Autocomplete: true, Name: "consul", @@ -52,6 +42,11 @@ func realMain() int { ErrorWriter: os.Stderr, } + if cli.IsVersion() { + cmd := version.New(ui, consulversion.GetHumanVersion()) + return cmd.Run(nil) + } + exitCode, err := cli.Run() if err != nil { fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())