Skip to content

Commit

Permalink
Allow graceful handling of no sarif files (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacSweers committed Nov 8, 2023
1 parent b02620e commit 9c98583
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/kotlin/slack/cli/sarif/MergeSarifReports.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public class MergeSarifReports :
)
.flag()

private val allowEmpty by
option(
"--allow-empty",
help = "Flag to allow graceful exiting if no sarif files are found.",
envvar = "SARIF_MERGING_ALLOW_EMPTY"
)
.flag()

private fun log(message: String) {
if (verbose) {
echo(message)
Expand Down Expand Up @@ -311,8 +319,13 @@ public class MergeSarifReports :
override fun run() {
val sarifFiles = findSarifFiles()
if (sarifFiles.isEmpty()) {
log("No sarif files found! Did you run lint/detekt first?")
exitProcess(1)
if (allowEmpty) {
println("No sarif files found, skipping merging")
exitProcess(0)
} else {
System.err.println("No sarif files found! Did you run lint/detekt first?")
exitProcess(1)
}
}
merge(sarifFiles)
}
Expand Down

0 comments on commit 9c98583

Please sign in to comment.