grokkit/config/config.go
Greg Gauthier 9bd3e1d00e refactor: add error handling and refactor git utilities
- Enhance error checking in all commands using git.Run
- Refactor git helper to return errors properly
- Fix README.md filename typo
- Update .gitignore with additional ignores
- Add fallback for config home dir
- Improve request handling in grok client
2026-03-01 12:08:49 +00:00

40 lines
794 B
Go

package config
import (
"os"
"path/filepath"
"github.com/spf13/viper"
)
func Load() {
home, err := os.UserHomeDir()
if err != nil {
// Fall back to current directory if home not found
home = "."
}
configPath := filepath.Join(home, ".config", "grokkit")
viper.SetConfigName("config")
viper.SetConfigType("toml")
viper.AddConfigPath(configPath)
viper.AddConfigPath(".")
viper.AutomaticEnv()
viper.SetDefault("default_model", "grok-4")
viper.SetDefault("temperature", 0.7)
// Config file is optional, so we ignore read errors
_ = viper.ReadInConfig()
}
func GetModel(flagModel string) string {
if flagModel != "" {
if alias := viper.GetString("aliases." + flagModel); alias != "" {
return alias
}
return flagModel
}
return viper.GetString("default_model")
}