File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
commonMain/kotlin/com/github/ajalt/clikt/core
commonTest/kotlin/com/github/ajalt/clikt/core Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -539,8 +539,14 @@ private fun Any.classSimpleName(): String = this::class.simpleName.orEmpty().spl
539
539
540
540
private fun CliktCommand.inferCommandName (): String {
541
541
val name = classSimpleName()
542
- if (name == " Command" ) return " command"
543
- return name.removeSuffix(" Command" ).replace(Regex (" ([a-z])([A-Z])" )) {
542
+
543
+ val suffixes = setOf (" Command" , " Commands" )
544
+ if (name in suffixes) return name.lowercase()
545
+
546
+ val nameWithoutSuffixes = suffixes.fold(name) { acc, s -> acc.removeSuffix(s) }
547
+ val lowerUpperRegex = Regex (" ([a-z])([A-Z])" )
548
+
549
+ return nameWithoutSuffixes.replace(lowerUpperRegex) {
544
550
" ${it.groupValues[1 ]} -${it.groupValues[2 ]} "
545
551
}.lowercase()
546
552
}
Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ import com.github.ajalt.clikt.parameters.groups.OptionGroup
6
6
import com.github.ajalt.clikt.parameters.groups.cooccurring
7
7
import com.github.ajalt.clikt.parameters.groups.mutuallyExclusiveOptions
8
8
import com.github.ajalt.clikt.parameters.groups.provideDelegate
9
- import com.github.ajalt.clikt.parameters.options.defaultLazy
10
9
import com.github.ajalt.clikt.parameters.options.flag
11
10
import com.github.ajalt.clikt.parameters.options.option
12
11
import com.github.ajalt.clikt.parameters.options.required
@@ -35,9 +34,11 @@ class CliktCommandTest {
35
34
class ListAllValuesCommand : TestCommand ()
36
35
class LGTMMeansLookingGoodToMe : TestCommand ()
37
36
class `nothing- to- change` : TestCommand ()
37
+ class ListCommands : NoOpCliktCommand ()
38
38
ListAllValuesCommand ().commandName shouldBe " list-all-values"
39
39
LGTMMeansLookingGoodToMe ().commandName shouldBe " lgtmmeans-looking-good-to-me"
40
40
`nothing- to- change`().commandName shouldBe " nothing-to-change"
41
+ ListCommands ().commandName shouldBe " list"
41
42
}
42
43
43
44
@Test
You can’t perform that action at this time.
0 commit comments