Closed adamsmd closed 4 months ago
Thanks for the detailed write-up! I fixed this in https://github.com/ajalt/mordant/pull/188, and I'll be making a bugfix release of mordant soon, so you can use it without waiting for a clikt release.
I also updated the clikt docs with your recommendation.
Summary
Using a Bash redirect with an argument file (@argfile) produces an error
Error: /dev/fd/63 not found
.Environment
Clikt: 4.4.0 Kotlin: 1.9.22 Platform: Tested on JVM with Linux. Unsure about others.
Code
The following code demonstraits this error:
src/main/kotlin/Main.kt
:build.gradle.kts
:Actual Output
Expected Output
Workaround
Uncommenting the
init
line inMain
produces the expected output.Cause
The default
argumentFileReader
is at https://github.com/ajalt/clikt/blob/2f8827814224e426a3557cbe52680985a6838b42/clikt/src/commonMain/kotlin/com/github/ajalt/clikt/core/Context.kt#L238-L239This calls
readArgumentFile
inMordantContext.kt
at https://github.com/ajalt/clikt/blob/2f8827814224e426a3557cbe52680985a6838b42/clikt-mordant/src/commonMain/kotlin/com/github/ajalt/clikt/core/MordantContext.kt#L55That calls
MultiplatformSystem.readFileAsUtf8()
at https://github.com/ajalt/mordant/blob/d24d2fa2794d57ac92e8a59445fe408ca0a598f1/mordant/src/commonMain/kotlin/com/github/ajalt/mordant/platform/MultiplatformSystem.kt#L34-L41That calls
readFileIfExists
at https://github.com/ajalt/mordant/blob/d24d2fa2794d57ac92e8a59445fe408ca0a598f1/mordant/src/jvmMain/kotlin/com/github/ajalt/mordant/internal/MppInternal.jvm.kt#L151-L155Which finally calls
java.io.File.isFile()
which returnsfalse
on pipes and devices.Recommended Fix
In https://github.com/ajalt/mordant/blob/d24d2fa2794d57ac92e8a59445fe408ca0a598f1/mordant/src/jvmMain/kotlin/com/github/ajalt/mordant/internal/MppInternal.jvm.kt#L151-L155, instead of calling
isFile()
, catch theFileNotFoundException
when opening the file.Note
The following documentation should be updated to reflect whatever fix is made here.
https://github.com/ajalt/clikt/blob/2f8827814224e426a3557cbe52680985a6838b42/clikt/src/commonMain/kotlin/com/github/ajalt/clikt/core/CoreCliktCommand.kt#L26-L30