@@ -28,10 +28,7 @@ import java.nio.file.Paths
28
28
import java.util.*
29
29
import java.util.concurrent.Callable
30
30
import java.util.concurrent.TimeUnit
31
- import kotlin.io.path.Path
32
- import kotlin.io.path.relativeTo
33
- import kotlin.io.path.relativeToOrSelf
34
- import kotlin.io.path.toPath
31
+ import kotlin.io.path.*
35
32
36
33
enum class DiagnosticSeverity (val severity : String , val value : Int ) {
37
34
INFO (" info" , Diagnostic .INFO ),
@@ -67,6 +64,9 @@ class ValidateSubcommand : Callable<Int> {
67
64
@CommandLine.Option (names = [" -l" , " --link-base" ])
68
65
var linkBase: java.net.URI ? = null
69
66
67
+ @CommandLine.Option (names = [" -d" , " --dir-base" ])
68
+ var dirBase: Path ? = null
69
+
70
70
@CommandLine.Option (names = [" -lf" , " --link-format" ], description = [" Specifies the link format" ," Valid values: ${LinkFormat .VALID_VALUES } " ] )
71
71
var linkFormat: LinkFormat = LinkFormat .CLI
72
72
@@ -92,6 +92,10 @@ class ValidateSubcommand : Callable<Int> {
92
92
return uri
93
93
}
94
94
95
+ private fun dirBase (): Path {
96
+ return dirBase ? : Paths .get(" " ).toAbsolutePath()
97
+ }
98
+
95
99
override fun call (): Int {
96
100
if (listRules) {
97
101
println (" Available validators:" )
@@ -198,7 +202,7 @@ class ValidateSubcommand : Callable<Int> {
198
202
OutputFormat .PHP_MARKDOWN -> MarkdownFormatPrinter (linkFormatter)
199
203
OutputFormat .TS_MARKDOWN -> MarkdownFormatPrinter (linkFormatter)
200
204
OutputFormat .DOTNET_MARKDOWN -> MarkdownFormatPrinter (linkFormatter)
201
- OutputFormat .GITHUB -> GithubFormatPrinter (linkFormatter)
205
+ OutputFormat .GITHUB -> GithubFormatPrinter (dirBase(), linkFormatter)
202
206
OutputFormat .JSON -> TODO ()
203
207
}
204
208
}
@@ -280,24 +284,30 @@ class ValidateSubcommand : Callable<Int> {
280
284
}
281
285
}
282
286
283
- class GithubFormatPrinter (override val linkFormatter : LinkFormatter ): FormatPrinter {
287
+ class GithubFormatPrinter (val dirBase : Path , override val linkFormatter : LinkFormatter ): FormatPrinter {
284
288
285
289
override fun print (fileURI : URI , result : RamlModelResult <Api >): String {
290
+ System .out .println (dirBase)
286
291
val validationResults = result.validationResults
287
292
var output = " "
288
293
if (validationResults.isNotEmpty()) {
289
294
val errors = validationResults.filter { diagnostic -> diagnostic.severity == Diagnostic .ERROR }
290
295
val warnings = validationResults.filter { diagnostic -> diagnostic.severity == Diagnostic .WARNING }
291
296
val infos = validationResults.filter { diagnostic -> diagnostic.severity == Diagnostic .INFO }
292
297
293
- if (errors.isNotEmpty()) output + = errors.joinToString(" \n " ) { " ::error file=${java.net. URI .create( it.location).path } ,line=${it.line} ::${it.detailMessage()} " }
294
- if (warnings.isNotEmpty()) output + = errors.joinToString(" \n " ) { " ::warning file=${java.net. URI .create( it.location).path } ,line=${it.line} ::${it.detailMessage()} " }
295
- if (infos.isNotEmpty()) output + = errors.joinToString(" \n " ) { " ::notice file=${java.net. URI .create( it.location).path } ,line=${it.line} ::${it.detailMessage()} " }
298
+ if (errors.isNotEmpty()) output + = errors.joinToString(" \n " ) { " ::error file=${it.toLocation(dirBase) } ,line=${it.line} ::${it.detailMessage()} " }
299
+ if (warnings.isNotEmpty()) output + = errors.joinToString(" \n " ) { " ::warning file=${it.toLocation(dirBase) } ,line=${it.line} ::${it.detailMessage()} " }
300
+ if (infos.isNotEmpty()) output + = errors.joinToString(" \n " ) { " ::notice file=${it.toLocation(dirBase) } ,line=${it.line} ::${it.detailMessage()} " }
296
301
297
302
return output
298
303
}
299
304
return " ::notice ::Specification at ${fileURI.toFileString()} is valid."
300
305
}
306
+
307
+ fun RamlDiagnostic.toLocation (filePath : Path ): Path {
308
+ return java.net.URI .create(this .location).toPath().relativeToOrSelf(filePath)
309
+ }
310
+
301
311
}
302
312
303
313
class MarkdownFormatPrinter (override val linkFormatter : LinkFormatter ): FormatPrinter {
0 commit comments