summaryrefslogtreecommitdiff
path: root/internal/cli/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cli/config.go')
-rw-r--r--internal/cli/config.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/cli/config.go b/internal/cli/config.go
new file mode 100644
index 0000000..6165458
--- /dev/null
+++ b/internal/cli/config.go
@@ -0,0 +1,38 @@
+package cli
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/spf13/viper"
+)
+
+// InitConfig initializes viper configuration
+func InitConfig(cfgFile string) {
+ if cfgFile != "" {
+ // Use config file from the flag
+ viper.SetConfigFile(cfgFile)
+ } else {
+ // Find home directory
+ home, err := os.UserHomeDir()
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error getting home directory: %v\n", err)
+ return
+ }
+
+ // Search config in home directory with name ".totalrecall" (without extension)
+ viper.AddConfigPath(home)
+ viper.AddConfigPath(".")
+ viper.SetConfigType("yaml")
+ viper.SetConfigName(".totalrecall")
+ }
+
+ // Environment variables
+ viper.SetEnvPrefix("TOTALRECALL")
+ viper.AutomaticEnv()
+
+ // Read config file
+ if err := viper.ReadInConfig(); err == nil {
+ fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
+ }
+}