fun process()

in baseline-cli/src/main/kotlin/BaselineCli.kt [16:53]


    fun process(options: BaselineOptions, cliPrinter: (String) -> Unit, errPrinter: (String) -> Unit): Int {
        if (!Files.exists(Paths.get(options.sarifPath))) {
            errPrinter("Please provide a valid SARIF report path")
            return ERROR_EXIT
        }
        val sarifReport = try {
            SarifUtil.readReport(Paths.get(options.sarifPath))
        } catch (e: Exception) {
            errPrinter("Error reading SARIF report: ${e.message}")
            return ERROR_EXIT
        }

        val resolveInspectionName: (String) -> String = { id ->
            RuleUtil.findRuleDescriptor(sarifReport, id)?.shortDescription?.text ?: id
        }
        val printer = CommandLineResultsPrinter(simpleMemoize(resolveInspectionName), cliPrinter)
        return if (options.baselinePath != null) {
            compareBaselineThreshold(
                sarifReport,
                Paths.get(options.sarifPath),
                Paths.get(options.baselinePath),
                options.thresholds,
                options.includeAbsent,
                printer,
                cliPrinter,
                errPrinter
            )
        } else {
            compareThreshold(
                sarifReport,
                Paths.get(options.sarifPath),
                options.thresholds,
                printer,
                cliPrinter,
                errPrinter
            )
        }
    }