ChronoTomato/internal/helper/config.go

33 lines
626 B
Go
Raw Normal View History

package helper
import (
"github.com/charmbracelet/log"
"gopkg.in/yaml.v3"
"os"
"path/filepath"
"strings"
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
)
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
}