Skip to content

Commit 8f3668b

Browse files
authored
Fix argfiles specified after subcommands (#574)
Fixes #570
1 parent df70736 commit 8f3668b

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# Changelog
22

33
## Unreleased
4+
### Fixed
5+
- Fixed `@argfiles` not being expanded when specified after a subcommand ([#570](https://github.com/ajalt/clikt/pull/570))
6+
47
## 5.0.2
58
### Changed
69
- Update Kotlin to 2.1.0
710

811
## 5.0.1
912
### Added
10-
- Added completion commands for suspending and chained commands. ([#553](https://github.com/ajalt/clikt/pull/553))
13+
- Added completion commands for suspending and chained commands. ([#553](https://github.com/ajalt/clikt/pull/553))
1114
- Added no-op suspending commands. ([#554](https://github.com/ajalt/clikt/pull/554))
1215

1316
### Changed

clikt/src/commonMain/kotlin/com/github/ajalt/clikt/core/Context.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class Context private constructor(
317317
*
318318
* The block should throw [FileNotFound] if the given `filename` cannot be read.
319319
*/
320-
var readArgumentFile: ((filename: String) -> String)? = null
320+
var readArgumentFile: ((filename: String) -> String)? = parent?.readArgumentFile
321321

322322
@Suppress("unused")
323323
@Deprecated("Renamed to readArgumentFile", ReplaceWith("readArgumentFile"))

test/src/commonTest/kotlin/com/github/ajalt/clikt/parsers/AtFileTest.kt

+17
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package com.github.ajalt.clikt.parsers
33
import com.github.ajalt.clikt.core.CliktCommand
44
import com.github.ajalt.clikt.core.UsageError
55
import com.github.ajalt.clikt.core.context
6+
import com.github.ajalt.clikt.core.subcommands
67
import com.github.ajalt.clikt.parameters.arguments.argument
78
import com.github.ajalt.clikt.parameters.arguments.multiple
9+
import com.github.ajalt.clikt.parameters.options.flag
810
import com.github.ajalt.clikt.parameters.options.option
911
import com.github.ajalt.clikt.testing.TestCommand
1012
import com.github.ajalt.clikt.testing.parse
@@ -151,6 +153,21 @@ class AtFileTest {
151153
C(false).withAtFiles("baz" to "bar").parse("foo @baz")
152154
}
153155

156+
@Test
157+
@JsName("atfile_after_subcommand")
158+
fun `atfile after subcommand`() {
159+
class C: TestCommand() {
160+
val o by option().flag()
161+
162+
override fun run_() {
163+
o shouldBe true
164+
}
165+
}
166+
167+
TestCommand().subcommands(C())
168+
.withAtFiles("f" to "--o").parse("c @f")
169+
}
170+
154171
@Test
155172
@JsName("disabling_atfile")
156173
fun `disabling atfile`() {

0 commit comments

Comments
 (0)