From 4255a1f83a2459849f143843f5625ff806842826 Mon Sep 17 00:00:00 2001 From: Madeline Hashcube Date: Thu, 28 May 2026 14:46:45 -0500 Subject: [PATCH] scaffolding of config has been put in place --- cmd/ytpm/sync.go | 2 +- config/config.go | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/cmd/ytpm/sync.go b/cmd/ytpm/sync.go index f548df3..e68b79d 100644 --- a/cmd/ytpm/sync.go +++ b/cmd/ytpm/sync.go @@ -87,7 +87,7 @@ func SyncSources() (int, error) { keyPath := sourcesPath + key + "/" err = os.Mkdir(keyPath, cacheInfo.Mode()) if err != nil { - if err.Error() != "mkdir " + keyPath + ": file exists" { + if !errors.Is(err, fs.ErrExist) { return 0, err } } diff --git a/config/config.go b/config/config.go index 9155e98..6cdc79e 100644 --- a/config/config.go +++ b/config/config.go @@ -1,6 +1,38 @@ package config -type Configuration struct{ - Authors []string - Default []string +import ( + "os" + "go.yaml.in/yaml/v4" +) + +type Settings struct{ + Authors []string `yaml:"authors"` + Categories []string `yaml:"categories"` +} + +func ReadConfig(path string) (Settings, error) { + s := Settings{} + if path == "" { + cfgDir, err := os.UserConfigDir() + if err != nil { return s, err } + path = cfgDir + "/ytpm.yaml" + } + + data, err := os.ReadFile(path) + if err != nil { + // TODO: Handle Error To Use a Default Config + return s, err + } + + err = yaml.Unmarshal(data, &s) + if err != nil { + return s, err + } + + return s, nil +} + +func GenerateDefaultConfig() (Settings, error) { + s := Settings{} + return s, nil } -- 2.51.2