MCPcopy Create free account
hub / github.com/dlvhdr/diffnav / getConfigFilePath

Function getConfigFilePath

pkg/config/config.go:51–91  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49}
50
51func getConfigFilePath() string {
52 var configDirs []string
53
54 // Environment variable override - useful for development or non-standard setups.
55 if dir := os.Getenv("DIFFNAV_CONFIG_DIR"); dir != "" {
56 if s, err := os.Stat(dir); err == nil && s.IsDir() {
57 return filepath.Join(dir, "config.yml")
58 }
59 }
60
61 // On macOS, check XDG_CONFIG_HOME first (if user explicitly set it),
62 // then fall back to ~/.config (common for CLI tools).
63 // os.UserConfigDir() already handles this for Linux.
64 if runtime.GOOS == "darwin" {
65 if xdgConfigDir := os.Getenv("XDG_CONFIG_HOME"); xdgConfigDir != "" {
66 configDirs = append(configDirs, xdgConfigDir)
67 }
68 if home := os.Getenv("HOME"); home != "" {
69 configDirs = append(configDirs, filepath.Join(home, ".config"))
70 }
71 }
72
73 // Standard OS-specific config directory.
74 if configDir, err := os.UserConfigDir(); err == nil {
75 configDirs = append(configDirs, configDir)
76 }
77
78 // Return the first config file that exists.
79 for _, dir := range configDirs {
80 configPath := filepath.Join(dir, "diffnav", "config.yml")
81 if _, err := os.Stat(configPath); err == nil {
82 return configPath
83 }
84 }
85
86 // If no config file exists, return the preferred path for creation.
87 if len(configDirs) > 0 {
88 return filepath.Join(configDirs[0], "diffnav", "config.yml")
89 }
90 return ""
91}
92
93func Load() Config {
94 cfg := DefaultConfig()

Callers 1

LoadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected