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/helper"
"git.smsvc.net/pomodoro/ChronoTomato/internal/websocket" "git.smsvc.net/pomodoro/ChronoTomato/internal/websocket"
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models" GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
) )
@ -15,25 +16,22 @@ func Start() {
cursor.Hide() cursor.Hide()
defer cursor.Show() defer cursor.Show()
var config ChronoTomato.Config
channel := make(chan GoTomato.ServerMessage, 2) channel := make(chan GoTomato.ServerMessage, 2)
parameter_url := flag.String("url", "", "GoTomato Server URL (eg ws://localhost:8080/ws)") parameter_url := flag.String("url", "", "GoTomato Server URL (eg ws://localhost:8080/ws)")
parameter_password := flag.String("password", "", "Control password for pomodoro session (optional)") 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() flag.Parse()
config := helper.ParseConfig(*configfile) if *configfile != "" {
config = helper.ParseConfig(*configfile)
url := *parameter_url
if url == "" {
url = config.URL
} }
if *parameter_password != "" { config.URL = *parameter_url
config.Password = *parameter_password config.Password = *parameter_password
}
conn := websocket.Connect(url) conn := websocket.Connect(config.URL)
go websocket.ProcessServerMessages(conn, channel) go websocket.ProcessServerMessages(conn, channel)
frontend.Handler(conn, config, channel) frontend.Handler(conn, config, channel)

View file

@ -17,16 +17,11 @@ func ParseConfig(filename string) ChronoTomato.Config {
} }
yamlFile, err := os.ReadFile(filename) yamlFile, err := os.ReadFile(filename)
if err != nil { if err != nil {
log.Warn("Error opening config file!", "reason", err) log.Fatal("Error opening config file!", "reason", err)
log.Warn("Using defaults")
return ChronoTomato.Config{
URL: "ws://localhost:8080/ws",
}
} }
err = yaml.Unmarshal(yamlFile, &config) err = yaml.Unmarshal(yamlFile, &config)
if err != nil { if err != nil {
log.Fatalf("Unmarshal: %v", err) log.Fatalf("Unmarshal: %v", err)
} }
return config return config
} }