Skip to content

Commit

Permalink
Group options passed to groupChoice in help (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajalt authored Sep 13, 2019
1 parent 3a0b254 commit e99df80
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

### Fixed
- Help output missing items when no help text is specified. ([#85](https://github.com/ajalt/clikt/issues/85))
- Help output not grouping option in groups passed to `groupChoice`. ([#88](https://github.com/ajalt/clikt/issues/88))

## [2.1.0] - 2019-05-23
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ interface ParameterGroupDelegate<out T> : ParameterGroup, ReadOnlyProperty<Clikt
* val userOptions by UserOptions()
* }
* ```
*
* ### Note:
*
* If you're using IntelliJ, bug KT-31319 prevents [provideDelegate] from being imported
* automatically, so until that's fixed, you'll need to add this import manually:
*
* `import com.github.ajalt.clikt.parameters.groups.provideDelegate`
*/
open class OptionGroup(
name: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface Option {
get() = when {
hidden -> null
else -> HelpFormatter.ParameterHelp.Option(names, secondaryNames, metavar, help, nvalues, helpTags,
groupName = if (this is GroupableOption) parameterGroup?.groupName else null)
groupName = if (this is GroupableOption) groupName ?: parameterGroup?.groupName else null)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.multiple
import com.github.ajalt.clikt.parameters.groups.OptionGroup
import com.github.ajalt.clikt.parameters.groups.cooccurring
import com.github.ajalt.clikt.parameters.groups.groupChoice
import com.github.ajalt.clikt.parameters.groups.mutuallyExclusiveOptions
import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.types.int
Expand Down Expand Up @@ -405,6 +406,36 @@ class CliktHelpFormatterTest {
""".trimMargin("|")
}

@Test
@Suppress("unused")
fun `integration test with choice group`() {
class G1 : OptionGroup("G1") {
val opt1 by option()
}
class G2 : OptionGroup("G2") {
val opt2 by option()
}
class C : TestCommand() {
val opt by option().groupChoice("g1" to G1(), "g2" to G2())
}

val c = C()

c.getFormattedHelp() shouldBe """
|Usage: c [OPTIONS]
|
|G1:
| --opt1 TEXT
|
|G2:
| --opt2 TEXT
|
|Options:
| --opt TEXT
| -h, --help Show this message and exit
""".trimMargin("|")
}

@Test
@Suppress("unused")
fun `integration test`() {
Expand Down
2 changes: 1 addition & 1 deletion docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ class FromDisk : LoadConfig("Options for loading from disk") {
val followSymlinks by option().flag()
}

class FromNetwork: LoadConfig("Option for loading from network") {
class FromNetwork: LoadConfig("Options for loading from network") {
val url by option().required()
val username by option().prompt()
val password by option().prompt(hideInput = true)
Expand Down

0 comments on commit e99df80

Please sign in to comment.