Skip to content

Commit da06426

Browse files
committed
feat(commands): Support checking the syntax of repository config files
Rework success messages with color, while at it. Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
1 parent a49fd20 commit da06426

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

plugins/commands/config/src/main/kotlin/ConfigCommand.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import com.github.ajalt.clikt.parameters.types.file
3131
import com.github.ajalt.mordant.rendering.Theme
3232

3333
import org.ossreviewtoolkit.model.config.OrtConfiguration
34+
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
35+
import org.ossreviewtoolkit.model.readValue
3436
import org.ossreviewtoolkit.plugins.api.OrtPlugin
3537
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
3638
import org.ossreviewtoolkit.plugins.commands.api.OrtCommand
@@ -99,9 +101,19 @@ class ConfigCommand(descriptor: PluginDescriptor = ConfigCommandFactory.descript
99101
runCatching {
100102
OrtConfiguration.load(file = this)
101103
}.onSuccess {
102-
echo("The syntax of the configuration file '$this' is valid.")
104+
echo(Theme.Default.success("The file '$canonicalPath' contains valid global ORT configuration."))
105+
}.recoverCatching {
106+
@Suppress("TooGenericExceptionCaught")
107+
try {
108+
readValue<RepositoryConfiguration>()
109+
} catch (t: Throwable) {
110+
throw t.initCause(it)
111+
}
112+
}.onSuccess {
113+
echo(Theme.Default.success("The file '$canonicalPath' contains valid repository ORT configuration."))
103114
}.onFailure {
104-
echo(Theme.Default.danger(it.collectMessages()))
115+
val message = "The file '$canonicalPath' neither contains valid global nor repository ORT configuration"
116+
echo(Theme.Default.danger("$message: ${it.collectMessages()}"))
105117
throw ProgramResult(2)
106118
}
107119
}

0 commit comments

Comments
 (0)