From b8ab0fa2bbd988d034272214c399f1b0a8c149f3 Mon Sep 17 00:00:00 2001 From: Viktor Varland Date: Tue, 8 Apr 2025 13:07:49 +0200 Subject: [PATCH] feat: load config from flag/env/fallback --- README.md | 25 ++++++++++++++++++++----- main.go | 15 +++++++++++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1f0ee4f..a2715f2 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,21 @@ go install git.meatbag.se/varl/subsyt@latest ``` +## running + +Configuration can be loaded from a file specified either by the env +variable `CONFIG` or `--config` flag. + +The `--config` flag has priority over `CONFIG` environment variable. + +``` +CONFIG="/path/to/config.toml" ./subsyt + +./subsyt --config="/patch/to/config" + +./subsyt # assumes "./config.toml" +``` + ## config `config.toml`: @@ -53,7 +68,7 @@ opml_file = "./opml.xml" # the opml file to use CGO_ENABLED=0 go build ``` -## Cookies +## cookies > [!WARNING] > Your account **MAY** be banned when using cookies ! @@ -64,7 +79,7 @@ E.g. from Chromium: yt-dlp --cookies-from-browser chromium --cookies cookies.txt ``` -## Scheduling +## scheduling ### systemd @@ -96,7 +111,7 @@ RandomizedDelaySec=30 WantedBy=timers.target ``` -## Container +## container ``` podman run --rm \ @@ -107,7 +122,7 @@ podman run --rm \ registry.meatbag.se/varl/subsyt ``` -## Result +## result ``` . @@ -135,6 +150,6 @@ podman run --rm \ │   └── tvshow.nfo ``` -## Generate OPML +## generate opml E.g. https://github.com/jeb5/YouTube-Subscriptions-RSS diff --git a/main.go b/main.go index 18219e7..97c978e 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "log" "os" "path/filepath" @@ -12,12 +13,22 @@ import ( ) func main() { - configPath := os.Getenv("CONFIG") + configPtr := flag.String("config", "", "path to config file") + flag.Parse() - if configPath == "" { + configEnv := os.Getenv("CONFIG") + + var configPath string + if *configPtr != "" { + configPath = *configPtr + } else if configEnv != "" { + configPath = configEnv + } else { configPath = "./config.toml" } + log.Println("resolved config file", configPath) + cfg, err := config.Load(configPath) if err != nil { panic(err)