Rationalized the default configuration file path and updated documentation
All checks were successful
ci/woodpecker/tag/release Pipeline was successful

This commit is contained in:
2026-05-14 20:48:12 -05:00
parent b09966f076
commit 77134c3c78
4 changed files with 85 additions and 4 deletions

View File

@@ -14,7 +14,15 @@ import (
"gopkg.in/yaml.v3"
)
const DefaultConfigPath = "/etc/scriptorium/config.yml"
const (
DefaultConfigPath = "/etc/scriptorium/config.yml"
DefaultConfigPathLocal = "/usr/local/etc/scriptorium/config.yml"
)
var defaultConfigSearchPaths = []string{
DefaultConfigPathLocal,
DefaultConfigPath,
}
var (
ErrConfigNotFound = errors.New("config file not found")
@@ -74,7 +82,24 @@ func LoadConfig(path string, explicit bool) (AppSettings, error) {
resolved := BuiltInDefaults()
configPath := strings.TrimSpace(path)
if configPath == "" {
configPath = DefaultConfigPath
if explicit {
configPath = DefaultConfigPath
} else {
for _, candidate := range defaultConfigSearchPaths {
if _, err := os.Stat(candidate); err == nil {
configPath = candidate
break
} else if !errors.Is(err, os.ErrNotExist) {
return AppSettings{}, fmt.Errorf("failed to stat config file %q: %w", candidate, err)
}
}
}
}
if configPath == "" {
if explicit {
return AppSettings{}, fmt.Errorf("%w: %s", ErrConfigNotFound, DefaultConfigPath)
}
return resolved, nil
}
configPath = filepath.Clean(configPath)