-
I've got a couple of tied options in my command: private val basePath by option()
.convert { it.toPath() }
.defaultLazy { ".".toPath() }
.validate {
if (!it.isDirectory()) {
fail("The base path '$it' does not exist or is not a valid directory")
}
}
private val configFile by option()
.convert { it.toPath() }
.defaultLazy { "./config.properties".toPath() }
.validate {
val tmpPath = basePath.resolve(it)
if (!tmpPath.isRegularFile()) {
fail("The configuration file '$tmpPath' does not exist or is not a valid file")
}
} I need to validate Note the |
Beta Was this translation helpful? Give feedback.
Answered by
ajalt
Nov 4, 2023
Replies: 1 comment 1 reply
-
private val basePath by option()
.path(mustExist = true, canBeFile = false)
.default(Path("."))
private val configFile by option()
.path()
.default(Path("config.properties"))
.validate {
val tmpPath = basePath.resolve(it)
if (!tmpPath.isRegularFile()) {
fail("The configuration file '$tmpPath' does not exist or is not a valid file")
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
lppedd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
validate
is explicitly run after everything has been parsed, so your approach is fine. The only thing I would change is to use the built-inpath
conversion, which includes some validation already.