mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 17:15:56 +00:00
move "config" to subcommand
This commit is contained in:
parent
02c3c6d3e6
commit
ed43eca004
3 changed files with 72 additions and 57 deletions
29
cmd/config.go
Normal file
29
cmd/config.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/pilosa/pilosa/ctl"
|
||||
)
|
||||
|
||||
var conf = ctl.NewConfigCommand(os.Stdin, os.Stdout, os.Stderr)
|
||||
|
||||
var confCmd = &cobra.Command{
|
||||
Use: "config",
|
||||
Short: "config - prints the default configuration",
|
||||
Long: `config prints the default configuration to stdout
|
||||
`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if err := conf.Run(context.Background()); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(confCmd)
|
||||
}
|
||||
|
|
@ -96,7 +96,6 @@ Usage:
|
|||
|
||||
The commands are:
|
||||
|
||||
config prints the default configuration
|
||||
import imports data from a CSV file
|
||||
export exports data to a CSV file
|
||||
sort sorts a data file for optimal import speed
|
||||
|
|
@ -126,8 +125,6 @@ func (m *Main) ParseFlags(args []string) error {
|
|||
fmt.Fprintln(m.Stderr, m.Usage())
|
||||
fmt.Fprintln(m.Stderr, "")
|
||||
return flag.ErrHelp
|
||||
case "config":
|
||||
m.Cmd = NewConfigCommand(m.Stdin, m.Stdout, m.Stderr)
|
||||
case "import":
|
||||
m.Cmd = pilosactl.NewImportCommand(m.Stdin, m.Stdout, m.Stderr)
|
||||
case "export":
|
||||
|
|
@ -167,60 +164,6 @@ type Command interface {
|
|||
Run(context.Context) error
|
||||
}
|
||||
|
||||
// ConfigCommand represents a command for printing a default config.
|
||||
type ConfigCommand struct {
|
||||
// Standard input/output
|
||||
Stdin io.Reader
|
||||
Stdout io.Writer
|
||||
Stderr io.Writer
|
||||
}
|
||||
|
||||
// NewConfigCommand returns a new instance of ConfigCommand.
|
||||
func NewConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *ConfigCommand {
|
||||
return &ConfigCommand{
|
||||
Stdin: stdin,
|
||||
Stdout: stdout,
|
||||
Stderr: stderr,
|
||||
}
|
||||
}
|
||||
|
||||
// ParseFlags parses command line flags from args.
|
||||
func (cmd *ConfigCommand) ParseFlags(args []string) error {
|
||||
fs := flag.NewFlagSet("pilosactl", flag.ContinueOnError)
|
||||
fs.SetOutput(ioutil.Discard)
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Usage returns the usage message to be printed.
|
||||
func (cmd *ConfigCommand) Usage() string {
|
||||
return strings.TrimSpace(`
|
||||
usage: pilosactl config
|
||||
|
||||
Prints the default configuration file to standard out.
|
||||
`)
|
||||
}
|
||||
|
||||
// Run executes the main program execution.
|
||||
func (cmd *ConfigCommand) Run(ctx context.Context) error {
|
||||
fmt.Fprintln(cmd.Stdout, strings.TrimSpace(`
|
||||
data-dir = "~/.pilosa"
|
||||
host = "localhost:15000"
|
||||
|
||||
[cluster]
|
||||
replicas = 1
|
||||
|
||||
[[cluster.node]]
|
||||
host = "localhost:15000"
|
||||
|
||||
[plugins]
|
||||
path = ""
|
||||
`)+"\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExportCommand represents a command for bulk exporting data from a server.
|
||||
type ExportCommand struct {
|
||||
// Remote host and port.
|
||||
|
|
|
|||
43
ctl/config.go
Normal file
43
ctl/config.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package ctl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ConfigCommand represents a command for printing a default config.
|
||||
type ConfigCommand struct {
|
||||
// Standard input/output
|
||||
Stdin io.Reader
|
||||
Stdout io.Writer
|
||||
Stderr io.Writer
|
||||
}
|
||||
|
||||
// NewConfigCommand returns a new instance of ConfigCommand.
|
||||
func NewConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *ConfigCommand {
|
||||
return &ConfigCommand{
|
||||
Stdin: stdin,
|
||||
Stdout: stdout,
|
||||
Stderr: stderr,
|
||||
}
|
||||
}
|
||||
|
||||
// Run executes the main program execution.
|
||||
func (cmd *ConfigCommand) Run(ctx context.Context) error {
|
||||
fmt.Fprintln(cmd.Stdout, strings.TrimSpace(`
|
||||
data-dir = "~/.pilosa"
|
||||
host = "localhost:15000"
|
||||
|
||||
[cluster]
|
||||
replicas = 1
|
||||
|
||||
[[cluster.node]]
|
||||
host = "localhost:15000"
|
||||
|
||||
[plugins]
|
||||
path = ""
|
||||
`)+"\n")
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue