Delegate configuration discovery to ConfigKit
This commit is contained in:
@@ -29,7 +29,6 @@ import (
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
const defaultConfigPath = "/usr/local/etc/notarius/config.yml"
|
||||
const usage = `Usage:
|
||||
notarius help
|
||||
notarius --version
|
||||
@@ -1085,39 +1084,6 @@ func runPipelines(args []string, stdout, stderr io.Writer, opts Options) int {
|
||||
}
|
||||
}
|
||||
|
||||
func discoverConfigPath(configPath string, opts Options) (string, error) {
|
||||
if path := strings.TrimSpace(configPath); path != "" {
|
||||
if err := requireConfigFile(path); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
if path, ok := opts.LookupEnv("NOTARIUS_CONFIG"); ok && strings.TrimSpace(path) != "" {
|
||||
path = strings.TrimSpace(path)
|
||||
if err := requireConfigFile(path); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
if _, err := os.Stat(defaultConfigPath); err == nil {
|
||||
return defaultConfigPath, nil
|
||||
} else if err != nil && !os.IsNotExist(err) {
|
||||
return "", fmt.Errorf("check default config %q: %w", defaultConfigPath, err)
|
||||
}
|
||||
return "", fmt.Errorf("config file not found; pass --config or set NOTARIUS_CONFIG")
|
||||
}
|
||||
|
||||
func requireConfigFile(path string) error {
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("config file %q is not available: %w", path, err)
|
||||
}
|
||||
if info.IsDir() {
|
||||
return fmt.Errorf("config file %q is a directory", path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseOnly(raw string) ([]string, error) {
|
||||
if strings.TrimSpace(raw) == "" {
|
||||
return nil, nil
|
||||
|
||||
Reference in New Issue
Block a user