mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-08 11:57:51 +00:00
code review tweaks
This commit is contained in:
parent
c7caea6b30
commit
555a514e37
8 changed files with 25 additions and 28 deletions
|
|
@ -10,6 +10,6 @@ import (
|
|||
func main() {
|
||||
if err := cmd.RootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(-1)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/pilosa/pilosa/server"
|
||||
)
|
||||
|
||||
var serve = server.NewMain()
|
||||
var serve = server.NewCommand()
|
||||
|
||||
var serveCmd = &cobra.Command{
|
||||
Use: "server",
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ func NewBackupCommand(stdin io.Reader, stdout, stderr io.Writer) *BackupCommand
|
|||
}
|
||||
}
|
||||
|
||||
// Run executes the main program execution.
|
||||
// Run executes the backup.
|
||||
func (cmd *BackupCommand) Run(ctx context.Context) error {
|
||||
// Validate arguments.
|
||||
if cmd.Path == "" {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ func NewConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *ConfigCommand
|
|||
}
|
||||
}
|
||||
|
||||
// Run executes the main program execution.
|
||||
// Run prints out the default config.
|
||||
func (cmd *ConfigCommand) Run(ctx context.Context) error {
|
||||
fmt.Fprintln(cmd.Stdout, strings.TrimSpace(`
|
||||
data-dir = "~/.pilosa"
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ func NewExportCommand(stdin io.Reader, stdout, stderr io.Writer) *ExportCommand
|
|||
}
|
||||
}
|
||||
|
||||
// Run executes the main program execution.
|
||||
// Run executes the export.
|
||||
func (cmd *ExportCommand) Run(ctx context.Context) error {
|
||||
logger := log.New(cmd.Stderr, "", log.LstdFlags)
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func NewSortCommand(stdin io.Reader, stdout, stderr io.Writer) *SortCommand {
|
|||
}
|
||||
}
|
||||
|
||||
// Run executes the main program execution.
|
||||
// Run executes the sort command.
|
||||
func (cmd *SortCommand) Run(ctx context.Context) error {
|
||||
// Open file for reading.
|
||||
f, err := os.Open(cmd.Path)
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ const (
|
|||
DefaultDataDir = "~/.pilosa"
|
||||
)
|
||||
|
||||
// Main represents the main program execution.
|
||||
type Main struct {
|
||||
// Command represents the state of the pilosa server command.
|
||||
type Command struct {
|
||||
Server *pilosa.Server
|
||||
|
||||
// Configuration options.
|
||||
|
|
@ -55,8 +55,8 @@ type Main struct {
|
|||
}
|
||||
|
||||
// NewMain returns a new instance of Main.
|
||||
func NewMain() *Main {
|
||||
return &Main{
|
||||
func NewCommand() *Command {
|
||||
return &Command{
|
||||
Server: pilosa.NewServer(),
|
||||
Config: pilosa.NewConfig(),
|
||||
|
||||
|
|
@ -66,8 +66,8 @@ func NewMain() *Main {
|
|||
}
|
||||
}
|
||||
|
||||
// Run executes the main program execution.
|
||||
func (m *Main) Run(args ...string) error {
|
||||
// Run executes the pilosa server.
|
||||
func (m *Command) Run(args ...string) error {
|
||||
// Notify user of config file.
|
||||
if m.ConfigPath != "" {
|
||||
fmt.Fprintf(m.Stdout, "Using config: %s\n", m.ConfigPath)
|
||||
|
|
@ -99,12 +99,12 @@ func (m *Main) Run(args ...string) error {
|
|||
}
|
||||
|
||||
// Close shuts down the server.
|
||||
func (m *Main) Close() error {
|
||||
func (m *Command) Close() error {
|
||||
return m.Server.Close()
|
||||
}
|
||||
|
||||
// ParseFlags parses command line flags from args.
|
||||
func (m *Main) SetupConfig(args []string) error {
|
||||
func (m *Command) SetupConfig(args []string) error {
|
||||
// Load config, if specified.
|
||||
if m.ConfigPath != "" {
|
||||
if _, err := toml.DecodeFile(m.ConfigPath, &m.Config); err != nil {
|
||||
|
|
@ -120,11 +120,8 @@ func (m *Main) SetupConfig(args []string) error {
|
|||
// Expand home directory.
|
||||
prefix := "~" + string(filepath.Separator)
|
||||
if strings.HasPrefix(m.Config.DataDir, prefix) {
|
||||
// u, err := user.Current()
|
||||
HomeDir := os.Getenv("HOME")
|
||||
/*if err != nil {
|
||||
return err
|
||||
} else*/if HomeDir == "" {
|
||||
if HomeDir == "" {
|
||||
return errors.New("data directory not specified and no home dir available")
|
||||
}
|
||||
m.Config.DataDir = filepath.Join(HomeDir, strings.TrimPrefix(m.Config.DataDir, prefix))
|
||||
|
|
|
|||
|
|
@ -304,7 +304,7 @@ path = "/path/to/plugins"
|
|||
|
||||
// Main represents a test wrapper for main.Main.
|
||||
type Main struct {
|
||||
*server.Main
|
||||
*server.Command
|
||||
|
||||
Stdin bytes.Buffer
|
||||
Stdout bytes.Buffer
|
||||
|
|
@ -318,16 +318,16 @@ func NewMain() *Main {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
m := &Main{Main: server.NewMain()}
|
||||
m := &Main{Command: server.NewCommand()}
|
||||
m.Config.DataDir = path
|
||||
m.Config.Host = "localhost:0"
|
||||
m.Main.Stdin = &m.Stdin
|
||||
m.Main.Stdout = &m.Stdout
|
||||
m.Main.Stderr = &m.Stderr
|
||||
m.Command.Stdin = &m.Stdin
|
||||
m.Command.Stdout = &m.Stdout
|
||||
m.Command.Stderr = &m.Stderr
|
||||
|
||||
if testing.Verbose() {
|
||||
m.Main.Stdout = io.MultiWriter(os.Stdout, m.Main.Stdout)
|
||||
m.Main.Stderr = io.MultiWriter(os.Stderr, m.Main.Stderr)
|
||||
m.Command.Stdout = io.MultiWriter(os.Stdout, m.Command.Stdout)
|
||||
m.Command.Stderr = io.MultiWriter(os.Stderr, m.Command.Stderr)
|
||||
}
|
||||
|
||||
return m
|
||||
|
|
@ -345,18 +345,18 @@ func MustRunMain() *Main {
|
|||
// Close closes the program and removes the underlying data directory.
|
||||
func (m *Main) Close() error {
|
||||
defer os.RemoveAll(m.Config.DataDir)
|
||||
return m.Main.Close()
|
||||
return m.Command.Close()
|
||||
}
|
||||
|
||||
// Reopen closes the program and reopens it.
|
||||
func (m *Main) Reopen() error {
|
||||
if err := m.Main.Close(); err != nil {
|
||||
if err := m.Command.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create new main with the same config.
|
||||
config := m.Config
|
||||
m.Main = server.NewMain()
|
||||
m.Command = server.NewCommand()
|
||||
m.Config = config
|
||||
|
||||
// Run new program.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue