Skip to content

Commit 4873616

Browse files
authored
fix: ensure status command shows the right message when using default (#91)
1 parent 401da6b commit 4873616

2 files changed

Lines changed: 16 additions & 21 deletions

File tree

cmd/neru/main.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,20 +1067,26 @@ func (a *App) handleIPCCommand(cmd ipc.Command) ipc.Response {
10671067

10681068
case "status":
10691069
cfgPath := a.ConfigPath
1070+
10701071
if cfgPath == "" {
10711072
// Fallback to the standard config path if daemon wasn't started
10721073
// with an explicit --config
1073-
cfgPath = config.GetConfigPath()
1074+
cfgPath = config.FindConfigFile()
10741075
}
10751076

1076-
// Expand ~ to home dir and resolve relative paths to absolute
1077-
if strings.HasPrefix(cfgPath, "~") {
1078-
if home, err := os.UserHomeDir(); err == nil {
1079-
cfgPath = filepath.Join(home, cfgPath[1:])
1077+
// If config file doesn't exist, return default config
1078+
if _, err := os.Stat(cfgPath); os.IsNotExist(err) {
1079+
cfgPath = "No config file found, using default config without config file"
1080+
} else {
1081+
// Expand ~ to home dir and resolve relative paths to absolute
1082+
if strings.HasPrefix(cfgPath, "~") {
1083+
if home, err := os.UserHomeDir(); err == nil {
1084+
cfgPath = filepath.Join(home, cfgPath[1:])
1085+
}
1086+
}
1087+
if abs, err := filepath.Abs(cfgPath); err == nil {
1088+
cfgPath = abs
10801089
}
1081-
}
1082-
if abs, err := filepath.Abs(cfgPath); err == nil {
1083-
cfgPath = abs
10841090
}
10851091

10861092
statusData := map[string]any{

internal/config/config.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func Load(path string) (*Config, error) {
211211

212212
// If path is empty, try default locations
213213
if path == "" {
214-
path = findConfigFile()
214+
path = FindConfigFile()
215215
}
216216

217217
// If config file doesn't exist, return default config
@@ -255,7 +255,7 @@ func Load(path string) (*Config, error) {
255255
}
256256

257257
// findConfigFile searches for config file in default locations
258-
func findConfigFile() string {
258+
func FindConfigFile() string {
259259
homeDir, err := os.UserHomeDir()
260260
if err != nil {
261261
return ""
@@ -276,17 +276,6 @@ func findConfigFile() string {
276276
return ""
277277
}
278278

279-
// GetConfigPath returns the expected config file path
280-
func GetConfigPath() string {
281-
homeDir, err := os.UserHomeDir()
282-
if err != nil {
283-
return ""
284-
}
285-
286-
// Prefer macOS standard location
287-
return filepath.Join(homeDir, "Library", "Application Support", "neru", "config.toml")
288-
}
289-
290279
// Validate validates the configuration
291280
func (c *Config) Validate() error {
292281
// Validate hint characters

0 commit comments

Comments
 (0)