mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
Cobra automatically displays usage messages, and also a gratuitous
"Error: [...]" line in some cases, when any error at all occurs
running a command. To suppress the usage message, you have to set
cmd.SilenceUsage to true. But the code that would do this doesn't
have access to it. To address this, we introduce a category of
"usage error", implemented with stdlib error wrapping (%w) and
use errors.Is to check for it. There's also utility functions
to do this checking automatically, or indeed, to handle wrapping
of the ctl.SomethingCommand and handle running it with a suitable
context and everything.
In fact, several of the places we're checking for usage errors,
we can never actually report one, but we're checking consistently
so that if we want to report usage errors, we can.
For instance, server.Start and (dax)server.Start don't ever
return usage errors, right now, but we're checking their responses
anyway.
(cherry picked from commit c681642734)
36 lines
1.4 KiB
Go
36 lines
1.4 KiB
Go
// Copyright 2021 Molecula Corp. All rights reserved.
|
|
package cmd
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/featurebasedb/featurebase/v3/ctl"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var cli *ctl.CLICommand
|
|
|
|
// newCLICommand runs the FeatureBase CLI subcommand for ingesting bulk data.
|
|
func newCLICommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
|
|
cli = ctl.NewCLICommand(stdin, stdout, stderr)
|
|
cliCmd := &cobra.Command{
|
|
Use: "cli",
|
|
Short: "Query FB with SQL3 from the command line",
|
|
Long: ``,
|
|
RunE: usageErrorWrapper(cli),
|
|
}
|
|
|
|
flags := cliCmd.Flags()
|
|
flags.StringVarP(&cli.Host, "host", "", cli.Host, "hostname of FeatureBase.")
|
|
flags.StringVarP(&cli.Port, "port", "", cli.Port, "port of FeatureBase.")
|
|
flags.StringVar(&cli.HistoryPath, "history-path", cli.HistoryPath, "path for history files.")
|
|
flags.StringVar(&cli.OrganizationID, "org-id", cli.OrganizationID, "OrganizationID.")
|
|
flags.StringVar(&cli.DatabaseID, "db-id", cli.DatabaseID, "DatabaseID.")
|
|
|
|
flags.StringVar(&cli.ClientID, "client-id", cli.ClientID, "Cognito Client ID for FeatureBase Cloud access.")
|
|
flags.StringVar(&cli.Region, "region", cli.Region, "Cloud region for FeatureBase Cloud access (e.g. us-east-2).")
|
|
flags.StringVar(&cli.Email, "email", cli.Email, "Email address for FeatureBase Cloud access.")
|
|
flags.StringVar(&cli.Password, "password", cli.Password, "Password for FeatureBase Cloud access.")
|
|
|
|
return cliCmd
|
|
}
|