func matchRegex()

in ibazel/output_runner/output_runner.go [138:162]


func matchRegex(optcmd []Optcmd, output *bytes.Buffer) ([]string, []string, [][]string) {
	var commandLines, commands []string
	var args [][]string
	distinctCommands := map[string]bool{}
	scanner := bufio.NewScanner(output)
	for scanner.Scan() {
		line := escapeCodeCleanerRegex.ReplaceAllLiteralString(scanner.Text(), "")
		for _, oc := range optcmd {
			re := regexp.MustCompile(oc.Regex)
			matches := re.FindStringSubmatch(line)
			if matches != nil && len(matches) >= 0 {
				command := convertArg(matches, oc.Command)
				cmdArgs := convertArgs(matches, oc.Args)
				fullCmd := strings.Join(append([]string{command}, cmdArgs...), " ")
				if _, found := distinctCommands[fullCmd]; !found {
					commandLines = append(commandLines, matches[0])
					commands = append(commands, command)
					args = append(args, cmdArgs)
					distinctCommands[fullCmd] = true
				}
			}
		}
	}
	return commandLines, commands, args
}