diff --git a/cmd/server.go b/cmd/server.go index c9d5659d5..2d686b2ea 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -26,11 +26,6 @@ on the configured port.`, serve.Server.Handler.Version = Version fmt.Fprintf(serve.Stderr, "Pilosa %s, build time %s\n", Version, BuildTime) - // Parse command line arguments. - if err := serve.SetupConfig(args); err != nil { - return err - } - // Start CPU profiling. if serve.CPUProfile != "" { f, err := os.Create(serve.CPUProfile) @@ -72,9 +67,10 @@ on the configured port.`, func init() { flags := serveCmd.Flags() - flags.StringVarP(&serve.ConfigPath, "config", "c", "", "Configuration file to read from") - flags.StringVarP(&serve.CPUProfile, "cpu-profile", "", "", "Where to store CPU profile") - flags.DurationVarP(&serve.CPUTime, "cpu-time", "", 30*time.Second, "CPU profile duration") + flags.StringVarP(&serve.ConfigPath, "config", "c", "", "Configuration file to read from.") + flags.StringVarP(&serve.Config.DataDir, "data-dir", "d", "~/.pilosa", "Directory to store pilosa data files.") + flags.StringVarP(&serve.CPUProfile, "cpu-profile", "", "", "Where to store CPU profile.") + flags.DurationVarP(&serve.CPUTime, "cpu-time", "", 30*time.Second, "CPU profile duration.") RootCmd.AddCommand(serveCmd) } diff --git a/server/server.go b/server/server.go index 85b3dbb77..15f2ad9b4 100644 --- a/server/server.go +++ b/server/server.go @@ -10,7 +10,6 @@ import ( "strings" "time" - "github.com/BurntSushi/toml" "github.com/pilosa/pilosa" ) @@ -55,9 +54,13 @@ func NewCommand() *Command { // 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) + prefix := "~" + string(filepath.Separator) + if strings.HasPrefix(m.Config.DataDir, prefix) { + HomeDir := os.Getenv("HOME") + 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)) } // Setup logging output. @@ -79,9 +82,7 @@ func (m *Command) Run(args ...string) error { if err := m.Server.Open(); err != nil { return err } - fmt.Fprintf(m.Stderr, "Listening as http://%s\n", m.Server.Host) - return nil } @@ -89,30 +90,3 @@ func (m *Command) Run(args ...string) error { func (m *Command) Close() error { return m.Server.Close() } - -// SetupConfig loads the config file if specified and sets state on the Command. -func (m *Command) SetupConfig(args []string) error { - // Load config, if specified. - if m.ConfigPath != "" { - if _, err := toml.DecodeFile(m.ConfigPath, &m.Config); err != nil { - return err - } - } - - // Use default data directory if one is not specified. - if m.Config.DataDir == "" { - m.Config.DataDir = DefaultDataDir - } - - // Expand home directory. - prefix := "~" + string(filepath.Separator) - if strings.HasPrefix(m.Config.DataDir, prefix) { - HomeDir := os.Getenv("HOME") - 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)) - } - - return nil -}