test config resolving targets

This commit is contained in:
Bel LaPointe
2023-11-06 12:38:11 -07:00
parent d36f9e74b3
commit 84aa7cb319
2 changed files with 92 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"os"
"path"
"path/filepath"
"strings"
)
@@ -54,7 +55,11 @@ func (config config) Targets() []string {
func (config config) targets() ([]string, error) {
patterns := []string{config.target, fmt.Sprintf("%s.*", config.target)}
if stat, err := os.Stat(config.target); err == nil && stat.IsDir() {
isDir := false
if stat, err := os.Stat(config.target); err == nil {
isDir = stat.IsDir()
}
if isDir {
patterns = []string{fmt.Sprintf("%s/*", config.target)}
}
@@ -68,6 +73,9 @@ func (config config) targets() ([]string, error) {
}
if len(result) == 0 {
if isDir {
return []string{path.Join(config.target, "root.yaml")}, nil
}
return []string{config.target}, nil
}
return result, nil