feat(influx): add version to influx CLI

closes: #14821
pull/18357/head
Johnny Steenbergen 2020-06-02 15:33:15 -07:00 committed by Johnny Steenbergen
parent 19a2496a28
commit 81a0982b00
2 changed files with 23 additions and 1 deletions

View File

@ -84,6 +84,8 @@ $(CMDS): $(SOURCES)
# Ease of use build for just the go binary
influxd: bin/$(GOOS)/influxd
influx: bin/$(GOOS)/influx
#
# Define targets for the web ui
#

View File

@ -10,6 +10,7 @@ import (
"path/filepath"
"strings"
"sync"
"time"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/bolt"
@ -27,6 +28,12 @@ import (
const maxTCPConnections = 10
var (
version = "dev"
commit = "none"
date = time.Now().UTC().Format(time.RFC3339)
)
func main() {
influxCmd := influxCmd()
if err := influxCmd.Execute(); err != nil {
@ -218,10 +225,23 @@ func (b *cmdInfluxBuilder) cmd(childCmdFns ...func(f *globalFlags, opt genericCL
// completion command goes last, after the walk, so that all
// commands have every flag listed in the bash|zsh completions.
cmd.AddCommand(completionCmd(cmd))
cmd.AddCommand(
completionCmd(cmd),
cmdVersion(),
)
return cmd
}
func cmdVersion() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Print the influx CLI version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Influx CLI %s (git: %s) build_date: %s\n", version, commit, date)
},
}
}
func influxCmd(opts ...genericCLIOptFn) *cobra.Command {
builder := newInfluxCmdBuilder(opts...)
return builder.cmd(