feat: add configuration file handling
- add helper function to parse configuration from a YAML file
- update command-line parameters to include a config file option
- remove hardcoded Pomodoro settings and use parsed config instead
- delete obsolete PomodoroSettings.go file
🤖
This commit is contained in:
parent
25e939f523
commit
bb790459c1
7 changed files with 69 additions and 26 deletions
26
internal/helper/config.go
Normal file
26
internal/helper/config.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"ChronoTomato/pkg/models"
|
||||
"github.com/charmbracelet/log"
|
||||
"gopkg.in/yaml.v2"
|
||||
"os"
|
||||
)
|
||||
|
||||
func ParseConfig(filename string) models.ConfigFile {
|
||||
var config models.ConfigFile
|
||||
yamlFile, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
log.Error("Error opening config file!", "reason", err)
|
||||
log.Info("Using defaults")
|
||||
return models.ConfigFile{
|
||||
URL: "ws://localhost:8080/ws",
|
||||
}
|
||||
}
|
||||
err = yaml.Unmarshal(yamlFile, &config)
|
||||
if err != nil {
|
||||
log.Fatalf("Unmarshal: %v", err)
|
||||
}
|
||||
return config
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue