From 14c1ddaf7c5468c5966b0c1585f19a5ff39c206d Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Thu, 9 May 2024 18:24:25 +0200 Subject: feat: enable setting config file path via command line --- import/main.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'import') 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) } -- cgit 1.4.1