Feature: Hide nested flags if hidden tag applied to parent
What type of PR is this?
- feature
What this PR does / why we need it:
This change introduces two new options InheritHidden and InheritDeprecated which can be used with the Parse* functions to mark all nested flags as either hidden or deprecated if a parent struct has been tagged as either hidden or deprecated.
For example given the following struct definition
type Details struct {
Name string
Age. int
}
type Config struct {
Details Details `flag:",hidden"`
Verbose bool
}
and a parser that looks like
var c Config
flags.ParseStruct(&c, flags.InheritHidden())
you would end up with something like
Flags:
--verbose
instead of
Flags:
--details-name
--details-age
--verbose
I had initially made this behaviour default behaviour, but refactored to options in order to not break backwards compatibility.
Which issue(s) this PR fixes:
n/a
Special notes for your reviewer:
I don't really like having both inheritHidden and hidden options, but I haven't been able to figure out how to combine them. If you have any suggestions please let me know.
Testing
New test cases have been added to parser_test.go to test the behaviour
Release Notes
* Add `InheritHidden` and `InheritDeprecated` options in order for flags to inherit the `hidden` or `deprecated` tags from a parent struct when using nested structs.
Actually, I think I've got it wrong, this change would remove the nested flags, not 'hide' them, let me see if I can do it properly.
@Juneezee - thanks for looking. I've cleaned up the commits and description and I think it's ready for review now.
Hi folks, any appetite for this change?