Skip to content

Commit

Permalink
Fix the '-c/--config' option
Browse files Browse the repository at this point in the history
  • Loading branch information
gvalkov committed Oct 14, 2018
1 parent f2b575a commit fffdf3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ server-side functionality is summarized entirely in its help message:

[//]: # (BEGIN HELP)
```
Usage: tailon [options] -c <config file>
Usage: tailon -c <config file>
Usage: tailon [options] <filespec> [<filespec> ...]
Tailon is a webapp for looking at and searching through files and streams.
Expand Down
27 changes: 13 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

const scriptDescription = `
Usage: tailon [options] -c <config file>
Usage: tailon -c <config file>
Usage: tailon [options] <filespec> [<filespec> ...]
Tailon is a webapp for looking at and searching through files and streams.
Expand Down Expand Up @@ -210,18 +210,7 @@ type Config struct {
FileSpecs []FileSpec
}

func makeConfig() *Config {
var configContent = defaultTomlConfig

if config.ConfigPath != "" {
if b, err := ioutil.ReadFile(config.ConfigPath); err != nil {
fmt.Fprintf(os.Stderr, "Error while reading config file '%s': %s\n", config.ConfigPath, err)
os.Exit(1)
} else {
configContent = string(b)
}
}

func makeConfig(configContent string) *Config {
defaults, commandSpecs := parseTomlConfig(configContent)

// Convert the list of bind addresses from []interface{} to []string.
Expand All @@ -245,7 +234,7 @@ func makeConfig() *Config {
var config = &Config{}

func main() {
config = makeConfig()
config = makeConfig(defaultTomlConfig)

printHelp := flag.BoolP("help", "h", false, "Show this help message and exit")
printConfigHelp := flag.BoolP("help-config", "e", false, "Show configuration file help and exit")
Expand Down Expand Up @@ -275,6 +264,16 @@ func main() {

config.BindAddr = strings.Split(*bindAddr, ",")

// If a configuration file is specified, read all options from it. This discards all options set on the command-line.
if config.ConfigPath != "" {
if b, err := ioutil.ReadFile(config.ConfigPath); err != nil {
fmt.Fprintf(os.Stderr, "Error reading config file '%s': %s\n", config.ConfigPath, err)
os.Exit(1)
} else {
config = makeConfig(string(b))
}
}

// Ensure that relative root is always '/' or '/$arg/'.
config.RelativeRoot = "/" + strings.TrimLeft(config.RelativeRoot, "/")
config.RelativeRoot = strings.TrimRight(config.RelativeRoot, "/") + "/"
Expand Down

0 comments on commit fffdf3f

Please sign in to comment.