featurebase/cmd/cli.go
Travis Turner 393721c0ce
Add viper (for env variable) support to CLI (#2251)
* Add viper (for env variable) support to CLI

* Move the "featurebase cli" sub-command to its own "fbsql" command

I don't know if this is the final name, but putting it here as a
placeholder for now.

* Handle single `--command` flags.

This also adds a printer interface so we can opt NOT to print setup
information in non-interactive mode.

* Add support for multiple `--command` flags in the same call

* Add support for multiple `--file` flags

* Move members related to Config into a separate struct

* Make sure non-interactive mode can connect to a database

* comment fix

* support control-C on readline

* Prevent connection message from printing in non-interactive mode

* Return errors (instead of printing them) in non-interactive mode
2023-02-16 20:41:39 -06:00

35 lines
909 B
Go

// Copyright 2021 Molecula Corp. All rights reserved.
package cmd
import (
"io"
"github.com/featurebasedb/featurebase/v3/cli"
"github.com/featurebasedb/featurebase/v3/ctl"
"github.com/featurebasedb/featurebase/v3/logger"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var cliCmd *cli.Command
// NewCLICommand runs the FeatureBase CLI subcommand.
func NewCLICommand(stderr io.Writer) *cobra.Command {
logdest := logger.NewStandardLogger(stderr)
cliCmd = cli.NewCommand(logdest)
cobraCmd := &cobra.Command{
Use: "fbsql",
Short: "Query FeatureBase with SQL from the command line",
Long: ``,
RunE: usageErrorWrapper(cliCmd),
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
v := viper.New()
return setAllConfig(v, cmd.Flags(), "FBSQL")
},
SilenceErrors: true,
}
// Attach flags to the command.
ctl.BuildCLIFlags(cobraCmd, cliCmd)
return cobraCmd
}