feat(config): Now expanding env vars before reading files

This commit is contained in:
2025-08-06 11:00:18 +02:00
parent fb4e3db827
commit 15a37f3e8c
2 changed files with 12 additions and 2 deletions

View File

@@ -50,7 +50,7 @@ const (
func ParseConfig(path string) (Config, error) {
var config Config
buffer, err := os.ReadFile(path)
buffer, err := os.ReadFile(os.ExpandEnv(path))
if err != nil {
return config, err
}

12
main.go
View File

@@ -1,6 +1,7 @@
package main
import (
"flag"
"log"
"os"
"os/signal"
@@ -19,8 +20,17 @@ func must[T any](obj T, err error) T {
func main() {
defer midi.CloseDriver()
var (
configPath string
printDebugMsgs bool
)
flag.StringVar(&configPath, "f", "$HOME/.config/midi-hid/config.yaml", "Config file")
flag.BoolVar(&printDebugMsgs, "debug", false, "Print debug messages")
flag.Parse()
log.Println("Starting...")
config := must(ParseConfig("config.yaml"))
config := must(ParseConfig(configPath))
controllerList := must(config.Construct())
defer controllerList.Stop()