break: configure via file OR cli parameters

no more defaults when no parameter passed!
This commit is contained in:
Sebastian Mark 2024-10-27 16:36:14 +01:00
parent 4f9bd664a3
commit f54e8486f1
2 changed files with 9 additions and 16 deletions

View file

@ -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.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)

View file

@ -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
}