I'm using code like
val outputDirectory by option()
.file(mustExist = false, canBeFile = false, canBeDir = true, mustBeWritable = true, mustBeReadable = false, canBeSymlink = true)
This fails with
Error: invalid value for --output-directory: directory "/foo/bar" is not writable.
if there is no "bar" directory inside the existing (and writable) "foo" directory. This is problematic as the code in run() does not even get a chance to create the directory as the option validation is done before run() is called.
At least on the JVM, the cause seems to be the use of Files.isWritable at
|
if (mustBeWritable && !Files.isWritable(it)) fail( |
which is documented to "check[s] that a file exists and that this Java virtual machine has appropriate privileges [...]". But actually, for a non-existing directory, it would be enough for the (closest existing) parent directory to be writable, so that the actual output directory can be created.
I'm using code like
This fails with
if there is no "bar" directory inside the existing (and writable) "foo" directory. This is problematic as the code in
run()does not even get a chance to create the directory as the option validation is done beforerun()is called.At least on the JVM, the cause seems to be the use of
Files.isWritableatclikt/clikt/src/jvmMain/kotlin/com/github/ajalt/clikt/parameters/types/path.kt
Line 40 in 0c0d60b
which is documented to "check[s] that a file exists and that this Java virtual machine has appropriate privileges [...]". But actually, for a non-existing directory, it would be enough for the (closest existing) parent directory to be writable, so that the actual output directory can be created.