diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index b57cb658..956822dd 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -4,6 +4,8 @@ import ( "bufio" "fmt" "io" + "maps" + "path" "regexp" "slices" "strconv" @@ -16,7 +18,7 @@ import ( var ( sepRegex = regexp.MustCompile(`^\s*---+\s*$`) strictSepRegex = regexp.MustCompile(`^---\n$`) - skipRegex = regexp.MustCompile(`^![-.:\w]+\s*$`) + skipRegex = regexp.MustCompile(`^![-.:*\w]+\s*$`) ) func normalize(key string) string { @@ -390,6 +392,16 @@ func assignMetadata(nodes []Node) (result []Node) { for _, node := range nodes { if node.ToolNode != nil { node.ToolNode.Tool.MetaData = metadata[node.ToolNode.Tool.Name] + for wildcard := range metadata { + if strings.Contains(wildcard, "*") { + if m, err := path.Match(wildcard, node.ToolNode.Tool.Name); m && err == nil { + if node.ToolNode.Tool.MetaData == nil { + node.ToolNode.Tool.MetaData = map[string]string{} + } + maps.Copy(node.ToolNode.Tool.MetaData, metadata[wildcard]) + } + } + } } result = append(result, node) } diff --git a/pkg/parser/parser_test.go b/pkg/parser/parser_test.go index 3967ebd5..f98b74e2 100644 --- a/pkg/parser/parser_test.go +++ b/pkg/parser/parser_test.go @@ -258,6 +258,11 @@ asdf2 --- !metadata:first:requirements.txt asdf + +--- +!metadata:f*r*:other + +foo bar ` tools, err := ParseTools(strings.NewReader(input)) require.NoError(t, err) @@ -266,5 +271,6 @@ asdf autogold.Expect(map[string]string{ "package.json": "foo=base\nf", "requirements.txt": "asdf", + "other": "foo bar", }).Equal(t, tools[0].MetaData) }