MCPcopy
hub / github.com/go-task/task / WildcardMatch

Method WildcardMatch

taskfile/ast/task.go:86–110  ·  view source on GitHub ↗

WildcardMatch will check if the given string matches the name of the Task and returns any wildcard values.

(name string)

Source from the content-addressed store, hash-verified

84
85// WildcardMatch will check if the given string matches the name of the Task and returns any wildcard values.
86func (t *Task) WildcardMatch(name string) (bool, []string) {
87 names := append([]string{t.Task}, t.Aliases...)
88
89 for _, taskName := range names {
90 regexStr := fmt.Sprintf("^%s$", strings.ReplaceAll(taskName, "*", "(.*)"))
91 regex := regexp.MustCompile(regexStr)
92 wildcards := regex.FindStringSubmatch(name)
93
94 if len(wildcards) == 0 {
95 continue
96 }
97
98 // Remove the first match, which is the full string
99 wildcards = wildcards[1:]
100 wildcardCount := strings.Count(taskName, "*")
101
102 if len(wildcards) != wildcardCount {
103 continue
104 }
105
106 return true, wildcards
107 }
108
109 return false, nil
110}
111
112func (t *Task) UnmarshalYAML(node *yaml.Node) error {
113 switch node.Kind {

Callers 1

FindMatchingTasksMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected