diff --git a/cli/agnosticv.go b/cli/agnosticv.go index 16d9b25..acc0464 100644 --- a/cli/agnosticv.go +++ b/cli/agnosticv.go @@ -424,33 +424,6 @@ func findCatalogItems(workdir string, hasFlags []string, relatedFlags []string, return nil } - if len(hasFlags) > 0 { - logDebug.Println("hasFlags", hasFlags) - // Here we need yaml.v3 in order to use jmespath - merged, _, err := mergeVars(p, mergeStrategies) - if err != nil { - // Print the error and move to next file - logErr.Println(err) - return nil - } - - for _, hasFlag := range hasFlags { - r, err := jmespath.Search(hasFlag, merged) - if err != nil { - logErr.Printf("ERROR: JMESPath '%q' not correct, %v", hasFlag, err) - return err - } - - logDebug.Printf("merged=%#v\n", merged) - logDebug.Printf("r=%#v\n", r) - - // If JMESPath expression does not match, skip file - if r == nil || r == false { - return nil - } - } - } - if len(relatedFlags) > 0 || len(orRelatedFlags) > 0 { mergeList, err := getMergeList(pAbs) related := extendMergeListWithRelated(pAbs, mergeList) @@ -473,6 +446,32 @@ func findCatalogItems(workdir string, hasFlags []string, relatedFlags []string, } if containsPath(related, orRelatedAbs) { + if len(hasFlags) > 0 { + logDebug.Println("hasFlags", hasFlags) + // Here we need yaml.v3 in order to use jmespath + merged, _, err := mergeVars(p, mergeStrategies) + if err != nil { + // Print the error and move to next file + logErr.Println(err) + return nil + } + + for _, hasFlag := range hasFlags { + r, err := jmespath.Search(hasFlag, merged) + if err != nil { + logErr.Printf("ERROR: JMESPath '%q' not correct, %v", hasFlag, err) + return err + } + + logDebug.Printf("merged=%#v\n", merged) + logDebug.Printf("r=%#v\n", r) + + // If JMESPath expression does not match, skip file + if r == nil || r == false { + return nil + } + } + } // Add catalog item to result result = append(result, p) return nil @@ -499,6 +498,33 @@ func findCatalogItems(workdir string, hasFlags []string, relatedFlags []string, } } + if len(hasFlags) > 0 { + logDebug.Println("hasFlags", hasFlags) + // Here we need yaml.v3 in order to use jmespath + merged, _, err := mergeVars(p, mergeStrategies) + if err != nil { + // Print the error and move to next file + logErr.Println(err) + return nil + } + + for _, hasFlag := range hasFlags { + r, err := jmespath.Search(hasFlag, merged) + if err != nil { + logErr.Printf("ERROR: JMESPath '%q' not correct, %v", hasFlag, err) + return err + } + + logDebug.Printf("merged=%#v\n", merged) + logDebug.Printf("r=%#v\n", r) + + // If JMESPath expression does not match, skip file + if r == nil || r == false { + return nil + } + } + } + result = append(result, p) return nil })