Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix argfiles specified after subcommands #574

Merged
merged 1 commit into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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