about summary refs log tree commit diff stats
path: root/import/main.go
diff options
context:
space:
mode:
authorAlan Pearce2024-05-09 18:24:25 +0200
committerAlan Pearce2024-05-09 19:27:57 +0200
commit14c1ddaf7c5468c5966b0c1585f19a5ff39c206d (patch)
tree91b7910c62fd9bc2bcf89c78847c311f80827a0d /import/main.go
parentfbc4c583a4e2759d6b8cdbb98de2c769918ddac8 (diff)
downloadsearchix-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.go18
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)
 	}