sflags icon indicating copy to clipboard operation
sflags copied to clipboard

Feature: Hide nested flags if hidden tag applied to parent

Open patdowney opened this issue 8 months ago • 2 comments

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.

patdowney avatar May 07 '25 22:05 patdowney

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.

patdowney avatar May 07 '25 23:05 patdowney

@Juneezee - thanks for looking. I've cleaned up the commits and description and I think it's ready for review now.

patdowney avatar May 13 '25 21:05 patdowney

Hi folks, any appetite for this change?

patdowney avatar Jul 16 '25 07:07 patdowney