Fix config system: rename config.json → metadata.json, fix config.yaml loading
- Renamed config.json to metadata.json to clarify purpose (database metadata) - Fixed config.yaml/config.json conflict by making Viper explicitly load only config.yaml - Added automatic migration from config.json to metadata.json on first read - Fixed jsonOutput variable shadowing across 22 command files - Updated bd init to create both metadata.json and config.yaml template - Fixed 5 failing JSON output tests - All tests passing Resolves config file confusion and makes config.yaml work correctly. Closes #178 (global flags), addresses config issues from #193 Amp-Thread-ID: https://ampcode.com/threads/T-e6ac8192-e18f-4ed7-83bc-4a5986718bb7 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const ConfigFileName = "config.json"
|
||||
const ConfigFileName = "metadata.json"
|
||||
|
||||
type Config struct {
|
||||
Database string `json:"database"`
|
||||
@@ -32,7 +32,31 @@ func Load(beadsDir string) (*Config, error) {
|
||||
|
||||
data, err := os.ReadFile(configPath) // #nosec G304 - controlled path from config
|
||||
if os.IsNotExist(err) {
|
||||
return nil, nil
|
||||
// Try legacy config.json location (migration path)
|
||||
legacyPath := filepath.Join(beadsDir, "config.json")
|
||||
data, err = os.ReadFile(legacyPath) // #nosec G304 - controlled path from config
|
||||
if os.IsNotExist(err) {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading legacy config: %w", err)
|
||||
}
|
||||
|
||||
// Migrate: parse legacy config, save as metadata.json, remove old file
|
||||
var cfg Config
|
||||
if err := json.Unmarshal(data, &cfg); err != nil {
|
||||
return nil, fmt.Errorf("parsing legacy config: %w", err)
|
||||
}
|
||||
|
||||
// Save to new location
|
||||
if err := cfg.Save(beadsDir); err != nil {
|
||||
return nil, fmt.Errorf("migrating config to metadata.json: %w", err)
|
||||
}
|
||||
|
||||
// Remove legacy file (best effort)
|
||||
_ = os.Remove(legacyPath)
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading config: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user