Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit config arg #30

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/thoj/go-ircevent"
"os"
"os/signal"
"strings"
"syscall"
)

Expand All @@ -20,6 +21,12 @@ var log = loggo.GetLogger("main")
var branch string
var revision string

var CONFIG_FILE_LOCATIONS = []string{
"/etc",
"/run/secrets",
".",
}

type IRCCat struct {
auth_channel string
channels mapset.Set
Expand All @@ -31,19 +38,24 @@ type IRCCat struct {

func main() {
debug := flag.Bool("debug", false, "Print raw IRC lines")
configFile := flag.String("config", "", "Path to config file to use")
flag.Parse()

loggo.ConfigureLoggers("<root>=INFO")
log.Infof("IRCCat %s (%s) starting...", branch, revision)
viper.SetConfigName("irccat")
viper.AddConfigPath("/run/secrets")
viper.AddConfigPath("/etc")
viper.AddConfigPath(".")
if *configFile != "" {
viper.SetConfigFile(*configFile)
} else {
viper.SetConfigName("irccat")
for _, p := range CONFIG_FILE_LOCATIONS {
viper.AddConfigPath(p)
}
}
var err error

err = viper.ReadInConfig()
if err != nil {
log.Errorf("Error reading config file - exiting. I'm looking for irccat.[json|yaml|toml|hcl] in . or /etc")
log.Errorf("Error reading config file - exiting. I'm looking for irccat.[json|yaml|toml|hcl] in one of %s", strings.Join(CONFIG_FILE_LOCATIONS, ", "))
return
}

Expand Down
Loading