From 336973443deb0781062ce1cd52ab71d42d0f0ec0 Mon Sep 17 00:00:00 2001 From: chris bell Date: Sat, 6 Jun 2026 17:03:54 -0500 Subject: [PATCH] Daemon remembers the config path if started with --config flag --- README.md | 2 +- main.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 841ecc7..f9b2ed8 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Alongside this project, I am developing a seperate web-based dashboard that can - [ ] Configuration - [x] Custom configuration path (passed to the daemon with a flag `--config`) - - [ ] Daemon instance remembers config path (*so you don't have to pass `--config` everytime you run an ipc command*) + - [x] Daemon instance remembers config path (*so you don't have to pass `--config` everytime you run an ipc command*) - [ ] Daemon listen port (kind of implemented, could be cleaner) - [x] Declarative Server configuration (Create servers in config) - [ ] More configuration options diff --git a/main.go b/main.go index abc40a6..8b83490 100644 --- a/main.go +++ b/main.go @@ -34,11 +34,30 @@ func main() { return } + configExplicitlySet := false + flag.Visit(func(f *flag.Flag) { + if f.Name == "config" { + configExplicitlySet = true + } + }) + + if !configExplicitlySet { + if envConfig := os.Getenv("VSSM_CONFIG_PATH"); envConfig != "" { + configFlag = &envConfig + } + } + absConfigPath, err := filepath.Abs(*configFlag) if err != nil { log.Fatalf("Failed to resolve absolute configuration path target: %v", err) } + if configExplicitlySet { + if err := os.Setenv("VSSM_CONFIG_PATH", absConfigPath); err != nil { + log.Fatalf("Warning: could not set VSSM_CONFIG_PATH: %v", err) + } + } + cfg, err := LoadOrCreateConfig(absConfigPath) if err != nil { log.Fatalf("Initialization failed: %v", err)