From f54e8486f1bd505a22d5119a9bcb1cdda7acb82c Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Sun, 27 Oct 2024 16:36:14 +0100 Subject: [PATCH] break: configure via file OR cli parameters no more defaults when no parameter passed! --- cmd/client/main.go | 18 ++++++++---------- internal/helper/config.go | 7 +------ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/cmd/client/main.go b/cmd/client/main.go index 191345f..89f8055 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -8,6 +8,7 @@ import ( "git.smsvc.net/pomodoro/ChronoTomato/internal/helper" "git.smsvc.net/pomodoro/ChronoTomato/internal/websocket" + ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models" GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models" ) @@ -15,25 +16,22 @@ func Start() { cursor.Hide() defer cursor.Show() + var config ChronoTomato.Config channel := make(chan GoTomato.ServerMessage, 2) parameter_url := flag.String("url", "", "GoTomato Server URL (eg ws://localhost:8080/ws)") parameter_password := flag.String("password", "", "Control password for pomodoro session (optional)") - configfile := flag.String("config", "~/.config/ChronoTomato.yml", "path to config file (optional)") + configfile := flag.String("config", "", "path to config file (optional)") flag.Parse() - config := helper.ParseConfig(*configfile) - - url := *parameter_url - if url == "" { - url = config.URL + if *configfile != "" { + config = helper.ParseConfig(*configfile) } - if *parameter_password != "" { - config.Password = *parameter_password - } + config.URL = *parameter_url + config.Password = *parameter_password - conn := websocket.Connect(url) + conn := websocket.Connect(config.URL) go websocket.ProcessServerMessages(conn, channel) frontend.Handler(conn, config, channel) diff --git a/internal/helper/config.go b/internal/helper/config.go index 6d5ee66..312e494 100644 --- a/internal/helper/config.go +++ b/internal/helper/config.go @@ -17,16 +17,11 @@ func ParseConfig(filename string) ChronoTomato.Config { } yamlFile, err := os.ReadFile(filename) if err != nil { - log.Warn("Error opening config file!", "reason", err) - log.Warn("Using defaults") - return ChronoTomato.Config{ - URL: "ws://localhost:8080/ws", - } + log.Fatal("Error opening config file!", "reason", err) } err = yaml.Unmarshal(yamlFile, &config) if err != nil { log.Fatalf("Unmarshal: %v", err) } return config - }