diff options
author | Alan Pearce | 2024-05-09 18:24:25 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-09 19:27:57 +0200 |
commit | 14c1ddaf7c5468c5966b0c1585f19a5ff39c206d (patch) | |
tree | 91b7910c62fd9bc2bcf89c78847c311f80827a0d /import/main.go | |
parent | fbc4c583a4e2759d6b8cdbb98de2c769918ddac8 (diff) | |
download | searchix-14c1ddaf7c5468c5966b0c1585f19a5ff39c206d.tar.lz searchix-14c1ddaf7c5468c5966b0c1585f19a5ff39c206d.tar.zst searchix-14c1ddaf7c5468c5966b0c1585f19a5ff39c206d.zip |
feat: enable setting config file path via command line
Diffstat (limited to 'import/main.go')
-rw-r--r-- | import/main.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/import/main.go b/import/main.go index 1e6b87d..b8ae633 100644 --- a/import/main.go +++ b/import/main.go @@ -13,15 +13,31 @@ import ( "searchix/internal/search" "strings" "time" + + "github.com/ardanlabs/conf/v3" ) const timeout = 30 * time.Minute +type Config struct { + ConfigFile string `conf:"short:c"` +} + func main() { if _, found := os.LookupEnv("DEBUG"); found { slog.SetLogLoggerLevel(slog.LevelDebug) } - cfg, err := config.GetConfig() + var runtimeConfig Config + help, err := conf.Parse("", &runtimeConfig) + if err != nil { + if errors.Is(err, conf.ErrHelpWanted) { + log.Println(help) + os.Exit(1) + } + log.Panicf("parsing runtime configuration: %v", err) + } + + cfg, err := config.GetConfig(runtimeConfig.ConfigFile) if err != nil { log.Fatal(err) } |