refactor: improve cli parameter handling

- streamline `main` functions
- refactor cli parameter handling
This commit is contained in:
Sebastian Mark 2024-10-27 17:01:23 +01:00
parent 34d4206f65
commit c2310f7735

View file

@ -12,27 +12,31 @@ import (
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models" 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() { func Start() {
flag.Parse()
cursor.Hide() cursor.Hide()
defer cursor.Show() defer cursor.Show()
var config ChronoTomato.Config // read cli parameters if no config file passed
channel := make(chan GoTomato.ServerMessage, 2) if *configfile == "" {
config.URL = *parameter_url
parameter_url := flag.String("url", "", "GoTomato Server URL (eg ws://localhost:8080/ws)") config.Password = *parameter_password
parameter_password := flag.String("password", "", "Control password for pomodoro session (optional)") } else {
configfile := flag.String("config", "", "path to config file (optional)") // otherwise read config
flag.Parse()
if *configfile != "" {
config = helper.ParseConfig(*configfile) config = helper.ParseConfig(*configfile)
} }
config.URL = *parameter_url
config.Password = *parameter_password
conn := websocket.Connect(config.URL) conn := websocket.Connect(config.URL)
channel := make(chan GoTomato.ServerMessage, 2)
go websocket.ProcessServerMessages(conn, channel) go websocket.ProcessServerMessages(conn, channel)
frontend.Handler(conn, config, channel) frontend.Handler(conn, config, channel)