All checks were successful
ci/woodpecker/tag/release Pipeline was successful
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package app
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
|
)
|
|
|
|
func resolvePipelineConfigPath(flagValue string) (string, error) {
|
|
return resolvePipelineConfigPathWithCandidates(flagValue, config.DefaultPipelineConfigSearchPaths)
|
|
}
|
|
|
|
func resolvePipelineConfigPathWithCandidates(flagValue string, candidates []string) (string, error) {
|
|
if explicit := strings.TrimSpace(flagValue); explicit != "" {
|
|
return explicit, nil
|
|
}
|
|
|
|
ordered := make([]string, 0, len(candidates))
|
|
for _, raw := range candidates {
|
|
path := strings.TrimSpace(raw)
|
|
if path == "" {
|
|
continue
|
|
}
|
|
ordered = append(ordered, path)
|
|
info, err := os.Stat(path)
|
|
if err == nil {
|
|
if info.IsDir() {
|
|
continue
|
|
}
|
|
return filepath.Clean(path), nil
|
|
}
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
continue
|
|
}
|
|
return "", fmt.Errorf("check default pipeline config %q: %w", path, err)
|
|
}
|
|
|
|
if len(ordered) == 0 {
|
|
return "", fmt.Errorf("no pipeline config path provided and no default locations configured")
|
|
}
|
|
return "", fmt.Errorf(
|
|
"no pipeline config path provided and no default pipeline config found; searched: %s",
|
|
strings.Join(ordered, ", "),
|
|
)
|
|
}
|