Skip to content

Commit 2f09a2d

Browse files
reid-spencerclaude
andcommitted
Fix sbt-riddl: ANSI version check and direct riddlc commands
Two fixes: - checkVersion() now passes --no-ansi-messages and strips any residual ANSI codes and [info] prefix from riddlc output, fixing NumberFormatException on version parsing - All tasks (validate, parse, bastify, prettify) now extract input-file from .conf and run riddlc commands directly (e.g. `riddlc validate file.riddl`) instead of using `riddlc from <conf> <command>`, which required each command to have its own block in the conf file Scripted test pinned to riddlcVersion := "1.13.0" so it downloads a real release instead of the dynver snapshot. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4d138a2 commit 2f09a2d

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

sbt-riddl/src/main/scala/com/ossuminc/riddl/sbt/plugin/RiddlSbtPlugin.scala

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,22 @@ object RiddlSbtPlugin extends AutoPlugin {
243243
} else { true }
244244
}
245245

246+
// Pattern to strip ANSI escape sequences from output
247+
private[plugin] val AnsiPattern: Regex =
248+
"\u001b\\[[0-9;]*m".r
249+
246250
private[plugin] def checkVersion(
247251
binary: File,
248252
minimumVersion: String
249253
): Unit = {
250-
val check = binary.getAbsolutePath + " version"
251-
val actualVersion = check.!!<.trim
254+
val check = Seq(
255+
binary.getAbsolutePath,
256+
"--no-ansi-messages", "version"
257+
)
258+
val raw = check.!!<.trim
259+
// Strip any residual ANSI codes and [info] prefix
260+
val actualVersion = AnsiPattern.replaceAllIn(raw, "")
261+
.replaceAll("(?i)\\[info]\\s*", "").trim
252262
val minVersion = minimumVersion.trim
253263
if (!versionSameOrLater(actualVersion, minVersion)) {
254264
throw new IllegalArgumentException(
@@ -510,7 +520,17 @@ object RiddlSbtPlugin extends AutoPlugin {
510520
batchConfOperation(
511521
binary, srcDir, confs, options, "validate", log
512522
) { conf =>
513-
Seq("from", conf.getAbsolutePath, "validate")
523+
extractInputFile(conf) match {
524+
case Some(inputFile) =>
525+
val riddlFile =
526+
conf.getParentFile / inputFile
527+
Seq("validate", riddlFile.getAbsolutePath)
528+
case None =>
529+
sys.error(
530+
"Could not extract input-file from " +
531+
conf.getAbsolutePath
532+
)
533+
}
514534
}
515535
}
516536
},
@@ -530,7 +550,17 @@ object RiddlSbtPlugin extends AutoPlugin {
530550
batchConfOperation(
531551
binary, srcDir, confs, options, "parse", log
532552
) { conf =>
533-
Seq("from", conf.getAbsolutePath, "parse")
553+
extractInputFile(conf) match {
554+
case Some(inputFile) =>
555+
val riddlFile =
556+
conf.getParentFile / inputFile
557+
Seq("parse", riddlFile.getAbsolutePath)
558+
case None =>
559+
sys.error(
560+
"Could not extract input-file from " +
561+
conf.getAbsolutePath
562+
)
563+
}
534564
}
535565
}
536566
},

sbt-riddl/src/sbt-test/sbt-riddl/simple/build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ lazy val root = (project in file("."))
33
.settings(
44
version := "0.1",
55
scalaVersion := "3.7.4",
6+
riddlcVersion := "1.13.0",
67
riddlcValidateOnCompile := false
78
)

0 commit comments

Comments
 (0)