ChronoTomato/internal/helper/config.go
Sebastian Mark f54e8486f1 break: configure via file OR cli parameters
no more defaults when no parameter passed!
2024-10-27 22:33:36 +01:00

27 lines
621 B
Go

package helper
import (
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
"github.com/charmbracelet/log"
"gopkg.in/yaml.v3"
"os"
"path/filepath"
"strings"
)
func ParseConfig(filename string) ChronoTomato.Config {
var config ChronoTomato.Config
if strings.HasPrefix(filename, "~/") {
dirname, _ := os.UserHomeDir()
filename = filepath.Join(dirname, filename[2:])
}
yamlFile, err := os.ReadFile(filename)
if err != nil {
log.Fatal("Error opening config file!", "reason", err)
}
err = yaml.Unmarshal(yamlFile, &config)
if err != nil {
log.Fatalf("Unmarshal: %v", err)
}
return config
}