WildcardMatch will check if the given string matches the name of the Task and returns any wildcard values.
(name string)
| 84 | |
| 85 | // WildcardMatch will check if the given string matches the name of the Task and returns any wildcard values. |
| 86 | func (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 | |
| 112 | func (t *Task) UnmarshalYAML(node *yaml.Node) error { |
| 113 | switch node.Kind { |