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

OptionGroup options protected instead of internal #368

Closed
untra opened this issue Aug 10, 2022 · 3 comments
Closed

OptionGroup options protected instead of internal #368

untra opened this issue Aug 10, 2022 · 3 comments

Comments

@untra
Copy link

untra commented Aug 10, 2022

Hi there! Big fan of clikt, this project is awesome. We have made a practice of extending certain clikt classes including CliktCommand to get additional or supportive functionality we've desired.

One capability we desire is to extend OptionGroup so our CLI can debug log the assigned values passed to all options. Our CLI has a DEBUG flag, and an increasing number of options. It would help greatly with debugging and maintainability to report all assigned settings passed into the OptionGroup.

https://github.com/ajalt/clikt/blob/master/clikt/src/commonMain/kotlin/com/github/ajalt/clikt/parameters/groups/ParameterGroup.kt#L76

We don't have a slick way of doing this currently, because access to OptionGroup.options is marked as internal. Any reason this field cannot be made protected instead, so advanced users can access all options in a group dynamically? This is a small change, but it would be a huge help.

@ajalt
Copy link
Owner

ajalt commented Aug 15, 2022

You can get the info you're looking for by getting all a command's options, then getting the groupName from each option's parameterHelp. If you need that actual OptionGroup instance, you can get it from the parameterGroup for any of the options that are GroupableOption. There are other types of groups that don't have an options property, so I'd rather not expose that property.

@sschuberth
Copy link
Contributor

sschuberth commented Dec 6, 2022

You can get the info you're looking for by getting all a command's options, then getting the groupName from each option's parameterHelp.

Bonus question: Is there a way to filter the resulting options to file options only (and their actual Filevalues)? When trying to use as NullableOption<File, File> I'm getting Cannot check for instance of erased type.

@ajalt
Copy link
Owner

ajalt commented Dec 6, 2022

Unfortunetely, since types are erased on the JVM, there's no way to filter on a specific delegate type. But you could filter for options with completionCandidates of type Path. It will require an unsafe cast though, and you'll need to know if your options use File or Path.

Alternately, you could cast them to OptionDelegate<*> and, for the ones where the cast succeeds, check the type of their value (o as? OptionDelegate<*>)?.value as? File. That's probably the way I would do it.

@ajalt ajalt closed this as completed Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants