fix(cli): honor local installation discovery precedence
This commit is contained in:
@@ -41,8 +41,8 @@ func Resolve(explicit string, environment func(string) string, workingDirectory
|
||||
return "", errors.New("installation discovery could not resolve the current directory")
|
||||
}
|
||||
|
||||
candidates := make(map[string]string)
|
||||
for directory := filepath.Clean(start); ; directory = filepath.Dir(directory) {
|
||||
candidates := make(map[string]string)
|
||||
for _, path := range discoveryCandidates(directory) {
|
||||
if hasArtifactsComponent(path) {
|
||||
continue
|
||||
@@ -57,6 +57,17 @@ func Resolve(explicit string, environment func(string) string, workingDirectory
|
||||
canonical := canonicalPath(path)
|
||||
candidates[canonical] = path
|
||||
}
|
||||
paths := make([]string, 0, len(candidates))
|
||||
for _, path := range candidates {
|
||||
paths = append(paths, path)
|
||||
}
|
||||
sort.Strings(paths)
|
||||
if len(paths) == 1 {
|
||||
return paths[0], nil
|
||||
}
|
||||
if len(paths) > 1 {
|
||||
return "", fmt.Errorf("multiple valid installation descriptors found: %s; use --installation <absolute-path>/%s", formatCandidates(paths, root.Path), installationFileName)
|
||||
}
|
||||
if directory == root.Path {
|
||||
break
|
||||
}
|
||||
@@ -66,19 +77,7 @@ func Resolve(explicit string, environment func(string) string, workingDirectory
|
||||
}
|
||||
}
|
||||
|
||||
paths := make([]string, 0, len(candidates))
|
||||
for _, path := range candidates {
|
||||
paths = append(paths, path)
|
||||
}
|
||||
sort.Strings(paths)
|
||||
switch len(paths) {
|
||||
case 1:
|
||||
return paths[0], nil
|
||||
case 0:
|
||||
return "", fmt.Errorf("installation descriptor not found from %s; run tht setup or use --installation <absolute-path>/%s", filepath.Clean(friendlyRoot), installationFileName)
|
||||
default:
|
||||
return "", fmt.Errorf("multiple valid installation descriptors found: %s; use --installation <absolute-path>/%s", formatCandidates(paths, root.Path), installationFileName)
|
||||
}
|
||||
return "", fmt.Errorf("installation descriptor not found from %s; run tht setup or use --installation <absolute-path>/%s", filepath.Clean(friendlyRoot), installationFileName)
|
||||
}
|
||||
|
||||
func formatCandidates(paths []string, root string) string {
|
||||
|
||||
Reference in New Issue
Block a user