Skip to content

Commit

Permalink
Fix argfiles specified after subcommands (#574)
Browse files Browse the repository at this point in the history
Fixes #570
  • Loading branch information
ajalt authored Feb 9, 2025
1 parent df70736 commit 8f3668b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Changelog

## Unreleased
### Fixed
- Fixed `@argfiles` not being expanded when specified after a subcommand ([#570](https://github.com/ajalt/clikt/pull/570))

## 5.0.2
### Changed
- Update Kotlin to 2.1.0

## 5.0.1
### Added
- Added completion commands for suspending and chained commands. ([#553](https://github.com/ajalt/clikt/pull/553))
- Added completion commands for suspending and chained commands. ([#553](https://github.com/ajalt/clikt/pull/553))
- Added no-op suspending commands. ([#554](https://github.com/ajalt/clikt/pull/554))

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class Context private constructor(
*
* The block should throw [FileNotFound] if the given `filename` cannot be read.
*/
var readArgumentFile: ((filename: String) -> String)? = null
var readArgumentFile: ((filename: String) -> String)? = parent?.readArgumentFile

@Suppress("unused")
@Deprecated("Renamed to readArgumentFile", ReplaceWith("readArgumentFile"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.github.ajalt.clikt.parsers
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.UsageError
import com.github.ajalt.clikt.core.context
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.multiple
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.testing.TestCommand
import com.github.ajalt.clikt.testing.parse
Expand Down Expand Up @@ -151,6 +153,21 @@ class AtFileTest {
C(false).withAtFiles("baz" to "bar").parse("foo @baz")
}

@Test
@JsName("atfile_after_subcommand")
fun `atfile after subcommand`() {
class C: TestCommand() {
val o by option().flag()

override fun run_() {
o shouldBe true
}
}

TestCommand().subcommands(C())
.withAtFiles("f" to "--o").parse("c @f")
}

@Test
@JsName("disabling_atfile")
fun `disabling atfile`() {
Expand Down

0 comments on commit 8f3668b

Please sign in to comment.