@@ -18,33 +18,30 @@ const (
1818)
1919
2020func includedOrExcluded (componentName string , requestedComponentNames []string ) (selectState , string , error ) {
21- // Check if the component has a leading dash indicating it should be excluded - this is done first so that exclusions precede inclusions
22- for _ , requestedComponent := range requestedComponentNames {
23- if strings .HasPrefix (requestedComponent , "-" ) {
24- // If the component glob matches one of the requested components, then return true
25- // This supports globbing with "path" in order to have the same behavior across OSes (if we ever allow namespaced components with /)
26- matched , err := path .Match (strings .TrimPrefix (requestedComponent , "-" ), componentName )
27- if err != nil {
28- return unknown , "" , err
29- }
30- if matched {
31- return excluded , requestedComponent , nil
32- }
33- }
34- }
35- // Check if the component matches a glob pattern and should be included
21+ // In unmatched cases we don't know if we should include or exclude yet
22+ var match string
23+ var matchType = unknown
24+
25+ // Check every component request, so last match get's priority
26+ // Order is assumed to match user input
3627 for _ , requestedComponent := range requestedComponentNames {
3728 // If the component glob matches one of the requested components, then return true
3829 // This supports globbing with "path" in order to have the same behavior across OSes (if we ever allow namespaced components with /)
39- matched , err := path .Match (requestedComponent , componentName )
30+ matched , err := path .Match (strings . TrimPrefix ( requestedComponent , "-" ) , componentName )
4031 if err != nil {
4132 return unknown , "" , err
4233 }
34+
4335 if matched {
44- return included , requestedComponent , nil
36+ match = requestedComponent
37+ // Exclusions are requests with the leading "-"
38+ if strings .HasPrefix (requestedComponent , "-" ) {
39+ matchType = excluded
40+ } else {
41+ matchType = included
42+ }
4543 }
4644 }
4745
48- // All other cases we don't know if we should include or exclude yet
49- return unknown , "" , nil
46+ return matchType , match , nil
5047}
0 commit comments