Skip to content

Commit

Permalink
cmd/lara: fix --config handling (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffie committed Jan 17, 2015
1 parent caae937 commit f75b87f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
7 changes: 2 additions & 5 deletions cmd/lara/config.go
Expand Up @@ -10,12 +10,9 @@ const defaultServerConfigPath = "larasync-server.gcfg"

// getServerConfig reads the best-matching config file, sanitizes it
// and returns the resulting config object.
func getServerConfig() (*config.ServerConfig, error) {
func getServerConfig(path string) (*config.ServerConfig, error) {
cfg := &config.ServerConfig{}
if configPath == "" {
configPath = defaultServerConfigPath
}
err := gcfg.ReadFileInto(cfg, configPath)
err := gcfg.ReadFileInto(cfg, path)
if err != nil {
return nil, err
}
Expand Down
4 changes: 0 additions & 4 deletions cmd/lara/flag.go
Expand Up @@ -4,10 +4,6 @@ import (
"github.com/codegangsta/cli"
)

var (
configPath string
)

// globalFlags returns the flags that should be
// registered to the main config file.
func (d *Dispatcher) globalFlags() []cli.Flag {
Expand Down
19 changes: 18 additions & 1 deletion cmd/lara/server.go
@@ -1,6 +1,8 @@
package main

import (
"path/filepath"

"github.com/inconshreveable/log15"

"github.com/hoffie/larasync/api"
Expand All @@ -10,7 +12,12 @@ import (
// serverAction starts the server process.
func (d *Dispatcher) serverAction() int {
d.setupLogging()
cfg, err := getServerConfig()
cfgPath, err := d.getServerConfigPath()
if err != nil {
log.Error("unable to get absolute server config path", log15.Ctx{"error": err})
return 1
}
cfg, err := getServerConfig(cfgPath)
if err != nil {
log.Error("unable to parse configuration", log15.Ctx{"error": err})
return 1
Expand All @@ -26,3 +33,13 @@ func (d *Dispatcher) serverAction() int {
log.Error("Error", log15.Ctx{"code": s.ListenAndServe()})
return 1
}

// getServerConfigPath returns the absolute path of the server config file
func (d *Dispatcher) getServerConfigPath() (string, error) {
path := d.context.String("config")
if path == "" {
path = defaultServerConfigPath
}
path, err := filepath.Abs(path)
return path, err
}

0 comments on commit f75b87f

Please sign in to comment.