Skip to content

Commit

Permalink
feat(cli): Add some coloring to output before program exit
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed May 3, 2024
1 parent 1fc611f commit 124b984
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 17 deletions.
3 changes: 2 additions & 1 deletion plugins/commands/advisor/src/main/kotlin/AdvisorCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.github.ajalt.clikt.parameters.options.required
import com.github.ajalt.clikt.parameters.options.split
import com.github.ajalt.clikt.parameters.types.enum
import com.github.ajalt.clikt.parameters.types.file
import com.github.ajalt.mordant.rendering.Theme

import java.time.Duration

Expand Down Expand Up @@ -133,7 +134,7 @@ class AdvisorCommand : OrtCommand(

val advisorRun = ortResultOutput.advisor
if (advisorRun == null) {
echo("No advisor run was created.")
echo(Theme.Default.danger("No advisor run was created."))
throw ProgramResult(1)
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/commands/analyzer/src/main/kotlin/AnalyzerCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.github.ajalt.clikt.parameters.options.required
import com.github.ajalt.clikt.parameters.options.split
import com.github.ajalt.clikt.parameters.types.enum
import com.github.ajalt.clikt.parameters.types.file
import com.github.ajalt.mordant.rendering.Theme

import java.time.Duration

Expand Down Expand Up @@ -206,7 +207,7 @@ class AnalyzerCommand : OrtCommand(

val analyzerRun = ortResult.analyzer
if (analyzerRun == null) {
echo("No analyzer run was created.")
echo(Theme.Default.danger("No analyzer run was created."))
throw ProgramResult(1)
}

Expand Down
8 changes: 4 additions & 4 deletions plugins/commands/compare/src/main/kotlin/CompareCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ class CompareCommand : OrtCommand(

override fun run() {
if (fileA == fileB) {
echo("The arguments point to the same file.")
echo(Theme.Default.success("The arguments point to the same file."))
throw ProgramResult(0)
}

if (fileA.extension != fileB.extension) {
echo("The file arguments need to be of the same type.")
echo(Theme.Default.danger("The file arguments need to be of the same type."))
throw ProgramResult(1)
}

Expand All @@ -126,7 +126,7 @@ class CompareCommand : OrtCommand(
)

if (resultA == resultB) {
echo("The ORT results are the same.")
echo(Theme.Default.success("The ORT results are the same."))
throw ProgramResult(0)
}

Expand Down Expand Up @@ -160,7 +160,7 @@ class CompareCommand : OrtCommand(
)

if (diff.isEmpty()) {
echo("The ORT results are the same.")
echo(Theme.Default.success("The ORT results are the same."))
throw ProgramResult(0)
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/commands/config/src/main/kotlin/ConfigCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.github.ajalt.clikt.parameters.options.convert
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.file
import com.github.ajalt.mordant.rendering.Theme

import org.ossreviewtoolkit.model.config.OrtConfiguration
import org.ossreviewtoolkit.model.config.OrtConfigurationWrapper
Expand Down Expand Up @@ -93,7 +94,7 @@ class ConfigCommand : OrtCommand(
}.onSuccess {
echo("The syntax of the configuration file '$this' is valid.")
}.onFailure {
echo(it.collectMessages())
echo(Theme.Default.danger(it.collectMessages()))
throw ProgramResult(2)
}
}
Expand Down
16 changes: 9 additions & 7 deletions plugins/commands/downloader/src/main/kotlin/DownloaderCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.github.ajalt.clikt.parameters.options.split
import com.github.ajalt.clikt.parameters.options.switch
import com.github.ajalt.clikt.parameters.types.enum
import com.github.ajalt.clikt.parameters.types.file
import com.github.ajalt.mordant.rendering.Theme

import java.io.File

Expand Down Expand Up @@ -212,9 +213,8 @@ class DownloaderCommand : OrtCommand(
echo("The $verb took $duration.")

if (failureMessages.isNotEmpty()) {
logger.error {
"The following failure(s) occurred:\n" + failureMessages.joinToString("\n--\n")
}
echo(Theme.Default.danger("The following failure(s) occurred:"))
failureMessages.joinToString("\n--\n").forEach(::echo)

throw ProgramResult(1)
}
Expand All @@ -224,10 +224,12 @@ class DownloaderCommand : OrtCommand(
val ortResult = readOrtResult(ortFile)

if (ortResult.analyzer?.result == null) {
logger.warn {
"Cannot run the downloader as the provided ORT result file '${ortFile.canonicalPath}' does " +
"not contain an analyzer result. Nothing will be downloaded."
}
echo(
Theme.Default.warning(
"Cannot run the downloader as the provided ORT result file '${ortFile.canonicalPath}' does " +
"not contain an analyzer result. Nothing will be downloaded."
)
)

throw ProgramResult(0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class RequirementsCommand : OrtCommand(
tools.getOrPut(category) { mutableListOf() } += instance
}
}.onFailure { e ->
logger.error { "There was an error instantiating $it: $e." }
echo(Theme.Default.danger("There was an error instantiating $it: $e."))
throw ProgramResult(1)
}
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/commands/scanner/src/main/kotlin/ScannerCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.github.ajalt.clikt.parameters.options.required
import com.github.ajalt.clikt.parameters.options.split
import com.github.ajalt.clikt.parameters.types.enum
import com.github.ajalt.clikt.parameters.types.file
import com.github.ajalt.mordant.rendering.Theme

import java.time.Duration

Expand Down Expand Up @@ -145,7 +146,7 @@ class ScannerCommand : OrtCommand(

val scannerRun = ortResult.scanner
if (scannerRun == null) {
echo("No scanner run was created.")
echo(Theme.Default.danger("No scanner run was created."))
throw ProgramResult(1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.required
import com.github.ajalt.clikt.parameters.types.enum
import com.github.ajalt.clikt.parameters.types.file
import com.github.ajalt.mordant.rendering.Theme

import java.net.URI

Expand Down Expand Up @@ -141,7 +142,7 @@ class UploadCurationsCommand : OrtCommand(
echo("Successfully uploaded $uploadedCurationsCount of $count curations.")

if (uploadedCurationsCount != count) {
echo("At least one curation failed to be uploaded.")
echo(Theme.Default.danger("At least one curation failed to be uploaded."))
throw ProgramResult(2)
}
}
Expand Down

0 comments on commit 124b984

Please sign in to comment.