Files
Mester Gábor 2dd6519168 Initial commit
2026-03-19 07:12:03 +01:00

39 lines
832 B
Go

package storage
import (
"os"
"path/filepath"
"gopkg.in/yaml.v3"
)
// Config holds persistent user preferences stored in .greq/config.yaml.
type Config struct {
Editor string `yaml:"editor,omitempty"` // e.g. "nvim", "nano", "code --wait"
}
var configPath = filepath.Join(RootDir, "config.yaml")
// LoadConfig reads .greq/config.yaml. Missing file returns an empty Config.
func LoadConfig() (Config, error) {
var cfg Config
data, err := os.ReadFile(configPath)
if err != nil {
if os.IsNotExist(err) {
return cfg, nil
}
return cfg, err
}
return cfg, yaml.Unmarshal(data, &cfg)
}
// SaveConfig writes cfg to .greq/config.yaml.
func SaveConfig(cfg Config) error {
_ = os.MkdirAll(RootDir, 0o755)
data, err := yaml.Marshal(&cfg)
if err != nil {
return err
}
return os.WriteFile(configPath, data, 0o644)
}