From c2310f77350e6f85ebbc1ae4dfb141da462a79f7 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Sun, 27 Oct 2024 17:01:23 +0100 Subject: [PATCH] refactor: improve cli parameter handling - streamline `main` functions - refactor cli parameter handling --- cmd/client/main.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/cmd/client/main.go b/cmd/client/main.go index 89f8055..7fdb573 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -12,27 +12,31 @@ import ( GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models" ) +var ( + config ChronoTomato.Config + parameter_url = flag.String("url", "", "GoTomato Server URL (eg ws://localhost:8080/ws)") + parameter_password = flag.String("password", "", "Control password for pomodoro session") + configfile = flag.String("config", "", "Path to config file") +) + func Start() { + flag.Parse() + 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", "", "path to config file (optional)") - flag.Parse() - - if *configfile != "" { + // read cli parameters if no config file passed + if *configfile == "" { + config.URL = *parameter_url + config.Password = *parameter_password + } else { + // otherwise read config config = helper.ParseConfig(*configfile) } - config.URL = *parameter_url - config.Password = *parameter_password - conn := websocket.Connect(config.URL) + channel := make(chan GoTomato.ServerMessage, 2) go websocket.ProcessServerMessages(conn, channel) frontend.Handler(conn, config, channel)