Skip to content

Commit

Permalink
Don't report an error for grouped short options with treatUnknownOpti…
Browse files Browse the repository at this point in the history
…onsAsArgs
  • Loading branch information
ajalt committed Jun 19, 2023
1 parent 127a220 commit bf1acca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

## 3.5.2
### Changed
- Updated Kotlin to 1.8.10
- Updated Kotlin to 1.8.22
-
### Fixed
- Fix `CliktCommand.prompt` on NodeJS targets that would hang due to KT-55817 ([#387](https://github.com/ajalt/clikt/issues/387))
- When `treatUnknownOptionsAsArgs` is true, grouped unknown short options will now be treated as arguments rather than reporting an error.

## 3.5.1
### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ internal object Parser {
if (i == 0) continue // skip the dash

val name = context.tokenTransformer(context, prefix + opt)
val option = optionsByName[name] ?: if (ignoreUnknown && tok.length == 2) {
val option = optionsByName[name] ?: if (ignoreUnknown) {
return OptParseResult(1, listOf(tok), emptyList())
} else {
val possibilities = when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,25 @@ class CliktCommandTest {
@Test
@JsName("treat_unknown_options_as_arguments_with_grouped_flag")
fun `treat unknown options as arguments with grouped flag`() {
class C(called: Boolean) : TestCommand(called = called, treatUnknownOptionsAsArgs = true) {
class C : TestCommand(treatUnknownOptionsAsArgs = true) {
val foo by option("-f").flag()
val args by argument().multiple()
}

val c = C(true)
c.parse("-f -g -i")
c.foo shouldBe true
c.args shouldBe listOf("-g", "-i")
if (skipDueToKT43490) return
shouldThrow<NoSuchOption> {
C(false).parse("-fgi")
}.message shouldBe "no such option: \"-g\""
with(C()) {
parse("-f -g -i")
foo shouldBe true
args shouldBe listOf("-g", "-i")
}
with(C()) {
parse("-f -gi")
foo shouldBe true
args shouldBe listOf("-gi")
}
with(C()) {
parse("-fgi")
foo shouldBe false
args shouldBe listOf("-fgi")
}
}
}
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencyResolutionManagement {
}
versionCatalogs {
create("libs") {
version("kotlin", "1.8.21")
version("kotlin", "1.8.22")

plugin("dokka", "org.jetbrains.dokka").version("1.8.10")
plugin("publish", "com.vanniktech.maven.publish").version("0.25.2")
Expand Down

0 comments on commit bf1acca

Please sign in to comment.