feat(influx): add version to influx CLI

closes: 
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
cmd/influx

View File

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

View File

@ -10,6 +10,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"sync" "sync"
"time"
"github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/bolt" "github.com/influxdata/influxdb/v2/bolt"
@ -27,6 +28,12 @@ import (
const maxTCPConnections = 10 const maxTCPConnections = 10
var (
version = "dev"
commit = "none"
date = time.Now().UTC().Format(time.RFC3339)
)
func main() { func main() {
influxCmd := influxCmd() influxCmd := influxCmd()
if err := influxCmd.Execute(); err != nil { 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 // completion command goes last, after the walk, so that all
// commands have every flag listed in the bash|zsh completions. // commands have every flag listed in the bash|zsh completions.
cmd.AddCommand(completionCmd(cmd)) cmd.AddCommand(
completionCmd(cmd),
cmdVersion(),
)
return cmd 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 { func influxCmd(opts ...genericCLIOptFn) *cobra.Command {
builder := newInfluxCmdBuilder(opts...) builder := newInfluxCmdBuilder(opts...)
return builder.cmd( return builder.cmd(