diff --git a/.gitignore b/.gitignore index 3d5978c323..f57b23b19f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ idpdb.bolt /dist # Project binaries. -/idp +/influx /idpd /ifqld /bin diff --git a/Makefile b/Makefile index 5c4cc519ab..a18e9bd44d 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ SOURCES := $(shell find . -name '*.go' -not -name '*_test.go') SOURCES_NO_VENDOR := $(shell find . -path ./vendor -prune -o -name "*.go" -not -name '*_test.go' -print) # List of binary cmds to build -CMDS := bin/idp bin/idpd bin/ifqld +CMDS := bin/influx bin/idpd bin/ifqld # List of utilities to build as part of the build process UTILS := bin/pigeon bin/cmpgen bin/goreleaser @@ -49,8 +49,8 @@ subdirs: $(SUBDIRS) bin/ifqld: $(SOURCES) $(GO_BUILD) -i -o bin/ifqld ./cmd/ifqld -bin/idp: $(SOURCES) - $(GO_BUILD) -i -o bin/idp ./cmd/idp +bin/influx: $(SOURCES) + $(GO_BUILD) -i -o bin/influx ./cmd/influx bin/idpd: $(SOURCES) $(GO_BUILD) -i -o bin/idpd ./cmd/idpd diff --git a/cmd/idp/main.go b/cmd/idp/main.go deleted file mode 100644 index f7fa790de8..0000000000 --- a/cmd/idp/main.go +++ /dev/null @@ -1,63 +0,0 @@ -package main - -import ( - "fmt" - "os" - - "github.com/spf13/cobra" - "github.com/spf13/viper" -) - -func main() { - Execute() -} - -var idpCmd = &cobra.Command{ - Use: "idp", - Short: "IDP Client", - Run: idpF, -} - -func init() { - idpCmd.AddCommand(authorizationCmd) - idpCmd.AddCommand(bucketCmd) - idpCmd.AddCommand(ifqlCmd) - idpCmd.AddCommand(organizationCmd) - idpCmd.AddCommand(userCmd) -} - -// Flags contains all the CLI flag values for idp. -type Flags struct { - token string - host string -} - -var flags Flags - -func init() { - viper.SetEnvPrefix("IDP") - - idpCmd.PersistentFlags().StringVarP(&flags.token, "token", "t", "", "API token to be used throughout client calls") - viper.BindEnv("TOKEN") - if h := viper.GetString("TOKEN"); h != "" { - flags.token = h - } - - idpCmd.PersistentFlags().StringVar(&flags.host, "host", "http://localhost:9999", "HTTP address of IDP") - viper.BindEnv("HOST") - if h := viper.GetString("HOST"); h != "" { - flags.host = h - } -} - -func idpF(cmd *cobra.Command, args []string) { - cmd.Usage() -} - -// Execute executes the idpd command -func Execute() { - if err := idpCmd.Execute(); err != nil { - fmt.Println(err) - os.Exit(1) - } -} diff --git a/cmd/idp/authorization.go b/cmd/influx/authorization.go similarity index 99% rename from cmd/idp/authorization.go rename to cmd/influx/authorization.go index 6a6ec551d2..1f74719b0c 100644 --- a/cmd/idp/authorization.go +++ b/cmd/influx/authorization.go @@ -6,7 +6,7 @@ import ( "os" "github.com/influxdata/platform" - "github.com/influxdata/platform/cmd/idp/internal" + "github.com/influxdata/platform/cmd/influx/internal" "github.com/influxdata/platform/http" "github.com/spf13/cobra" ) diff --git a/cmd/idp/bucket.go b/cmd/influx/bucket.go similarity index 99% rename from cmd/idp/bucket.go rename to cmd/influx/bucket.go index 67d378ede1..f00223dbf5 100644 --- a/cmd/idp/bucket.go +++ b/cmd/influx/bucket.go @@ -7,7 +7,7 @@ import ( "time" "github.com/influxdata/platform" - "github.com/influxdata/platform/cmd/idp/internal" + "github.com/influxdata/platform/cmd/influx/internal" "github.com/influxdata/platform/http" "github.com/spf13/cobra" ) diff --git a/cmd/idp/internal/tabwriter.go b/cmd/influx/internal/tabwriter.go similarity index 100% rename from cmd/idp/internal/tabwriter.go rename to cmd/influx/internal/tabwriter.go diff --git a/cmd/influx/main.go b/cmd/influx/main.go new file mode 100644 index 0000000000..b7de557973 --- /dev/null +++ b/cmd/influx/main.go @@ -0,0 +1,64 @@ +package main + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +func main() { + Execute() +} + +var influxCmd = &cobra.Command{ + Use: "influx", + Short: "Influx Client", + Run: influxF, +} + +func init() { + influxCmd.AddCommand(authorizationCmd) + influxCmd.AddCommand(bucketCmd) + influxCmd.AddCommand(replCmd) + influxCmd.AddCommand(queryCmd) + influxCmd.AddCommand(organizationCmd) + influxCmd.AddCommand(userCmd) +} + +// Flags contains all the CLI flag values for influx. +type Flags struct { + token string + host string +} + +var flags Flags + +func init() { + viper.SetEnvPrefix("INFLUX") + + influxCmd.PersistentFlags().StringVarP(&flags.token, "token", "t", "", "API token to be used throughout client calls") + viper.BindEnv("TOKEN") + if h := viper.GetString("TOKEN"); h != "" { + flags.token = h + } + + influxCmd.PersistentFlags().StringVar(&flags.host, "host", "http://localhost:9999", "HTTP address of Influx") + viper.BindEnv("HOST") + if h := viper.GetString("HOST"); h != "" { + flags.host = h + } +} + +func influxF(cmd *cobra.Command, args []string) { + cmd.Usage() +} + +// Execute executes the influx command +func Execute() { + if err := influxCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} diff --git a/cmd/idp/organization.go b/cmd/influx/organization.go similarity index 98% rename from cmd/idp/organization.go rename to cmd/influx/organization.go index 3257af62fe..845488a513 100644 --- a/cmd/idp/organization.go +++ b/cmd/influx/organization.go @@ -6,7 +6,7 @@ import ( "os" "github.com/influxdata/platform" - "github.com/influxdata/platform/cmd/idp/internal" + "github.com/influxdata/platform/cmd/influx/internal" "github.com/influxdata/platform/http" "github.com/spf13/cobra" ) diff --git a/cmd/idp/ifql.go b/cmd/influx/query.go similarity index 60% rename from cmd/idp/ifql.go rename to cmd/influx/query.go index c5f5abdb7d..edbdc5f069 100644 --- a/cmd/idp/ifql.go +++ b/cmd/influx/query.go @@ -21,90 +21,41 @@ import ( "github.com/spf13/viper" ) -var ifqlCmd = &cobra.Command{ - Use: "ifql", - Short: "Commands to interact with an IFQL server", - Run: ifqlF, +var queryCmd = &cobra.Command{ + Use: "query [query literal or @/path/to/query.ifql]", + Short: "Execute an IFQL query", + Long: `Execute a literal IFQL query provided as a string, + or execute a literal IFQL query contained in a file by specifying the file prefixed with an @ sign.`, + Args: cobra.ExactArgs(1), + Run: ifqlQueryF, } -var ifqlFlags struct { +var queryFlags struct { StorageHosts string OrgID string Verbose bool } func init() { - ifqlCmd.PersistentFlags().StringVar(&ifqlFlags.StorageHosts, "storage-hosts", "localhost:8082", "Comma-separated list of storage hosts") + queryCmd.PersistentFlags().StringVar(&queryFlags.StorageHosts, "storage-hosts", "localhost:8082", "Comma-separated list of storage hosts") viper.BindEnv("STORAGE_HOSTS") if h := viper.GetString("STORAGE_HOSTS"); h != "" { - ifqlFlags.StorageHosts = h + queryFlags.StorageHosts = h } - ifqlCmd.PersistentFlags().BoolVarP(&ifqlFlags.Verbose, "verbose", "v", false, "Verbose output") + queryCmd.PersistentFlags().BoolVarP(&queryFlags.Verbose, "verbose", "v", false, "Verbose output") viper.BindEnv("VERBOSE") if viper.GetBool("VERBOSE") { - ifqlFlags.Verbose = true + queryFlags.Verbose = true } - ifqlCmd.PersistentFlags().StringVar(&ifqlFlags.OrgID, "org-id", "", "Organization ID") + queryCmd.PersistentFlags().StringVar(&queryFlags.OrgID, "org-id", "", "Organization ID") viper.BindEnv("ORG_ID") if h := viper.GetString("ORG_ID"); h != "" { - ifqlFlags.OrgID = h + queryFlags.OrgID = h } } -func ifqlF(cmd *cobra.Command, args []string) { - cmd.Usage() -} - -func init() { - ifqlCmd.AddCommand(&cobra.Command{ - Use: "repl", - Short: "Interactive IFQL REPL (read-eval-print-loop)", - Args: cobra.NoArgs, - Run: ifqlReplF, - }) -} - -func ifqlReplF(cmd *cobra.Command, args []string) { - hosts, err := storageHostReader(strings.Split(ifqlFlags.StorageHosts, ",")) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - - org, err := orgID(ifqlFlags.OrgID) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - - buckets, err := bucketService(flags.host, flags.token) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - - r, err := getIFQLREPL(hosts, buckets, org, ifqlFlags.Verbose) - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - - r.Run() -} - -func init() { - ifqlCmd.AddCommand(&cobra.Command{ - Use: "query [query literal or @/path/to/query.ifql]", - Short: "Execute an IFQL query", - Long: `Execute a literal IFQL query provided as a string, - or execute a literal IFQL query contained in a file by specifying the file prefixed with an @ sign.`, - Args: cobra.ExactArgs(1), - Run: ifqlQueryF, - }) -} - func ifqlQueryF(cmd *cobra.Command, args []string) { q, err := repl.LoadQuery(args[0]) if err != nil { @@ -112,13 +63,13 @@ func ifqlQueryF(cmd *cobra.Command, args []string) { os.Exit(1) } - hosts, err := storageHostReader(strings.Split(ifqlFlags.StorageHosts, ",")) + hosts, err := storageHostReader(strings.Split(queryFlags.StorageHosts, ",")) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } - org, err := orgID(ifqlFlags.OrgID) + org, err := orgID(queryFlags.OrgID) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) @@ -130,7 +81,7 @@ func ifqlQueryF(cmd *cobra.Command, args []string) { os.Exit(1) } - r, err := getIFQLREPL(hosts, buckets, org, ifqlFlags.Verbose) + r, err := getIFQLREPL(hosts, buckets, org, queryFlags.Verbose) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) @@ -166,7 +117,7 @@ func bucketService(addr, token string) (platform.BucketService, error) { func orgID(org string) (ifqlid.ID, error) { var oid ifqlid.ID - err := oid.DecodeFromString(ifqlFlags.OrgID) + err := oid.DecodeFromString(org) return oid, err } diff --git a/cmd/influx/repl.go b/cmd/influx/repl.go new file mode 100644 index 0000000000..9277445b2d --- /dev/null +++ b/cmd/influx/repl.go @@ -0,0 +1,71 @@ +package main + +import ( + "fmt" + "os" + "strings" + + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var replCmd = &cobra.Command{ + Use: "repl", + Short: "Interactive REPL (read-eval-print-loop)", + Args: cobra.NoArgs, + Run: replF, +} + +var replFlags struct { + StorageHosts string + OrgID string + Verbose bool +} + +func init() { + replCmd.PersistentFlags().StringVar(&replFlags.StorageHosts, "storage-hosts", "localhost:8082", "Comma-separated list of storage hosts") + viper.BindEnv("STORAGE_HOSTS") + if h := viper.GetString("STORAGE_HOSTS"); h != "" { + replFlags.StorageHosts = h + } + + replCmd.PersistentFlags().BoolVarP(&replFlags.Verbose, "verbose", "v", false, "Verbose output") + viper.BindEnv("VERBOSE") + if viper.GetBool("VERBOSE") { + replFlags.Verbose = true + } + + replCmd.PersistentFlags().StringVar(&replFlags.OrgID, "org-id", "", "Organization ID") + viper.BindEnv("ORG_ID") + if h := viper.GetString("ORG_ID"); h != "" { + replFlags.OrgID = h + } +} + +func replF(cmd *cobra.Command, args []string) { + hosts, err := storageHostReader(strings.Split(replFlags.StorageHosts, ",")) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + org, err := orgID(replFlags.OrgID) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + buckets, err := bucketService(flags.host, flags.token) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + r, err := getIFQLREPL(hosts, buckets, org, replFlags.Verbose) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + r.Run() +} diff --git a/cmd/idp/user.go b/cmd/influx/user.go similarity index 98% rename from cmd/idp/user.go rename to cmd/influx/user.go index f3d2454dce..8daef8e7cd 100644 --- a/cmd/idp/user.go +++ b/cmd/influx/user.go @@ -6,7 +6,7 @@ import ( "os" "github.com/influxdata/platform" - "github.com/influxdata/platform/cmd/idp/internal" + "github.com/influxdata/platform/cmd/influx/internal" "github.com/influxdata/platform/http" "github.com/spf13/cobra" )