Skip to content

Conversation

@patdowney
Copy link
Contributor

@patdowney patdowney commented May 7, 2025

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 patdowney requested a review from a team as a code owner May 7, 2025 22:37
@patdowney
Copy link
Contributor Author

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 Juneezee marked this pull request as draft May 13, 2025 01:15
When specified as options to the `Parse*` functions they change the behaviour
of flag generation such that any structs tagged as `deprecated` or `hidden`
tags applied to structs will be inherited by all child values.
@patdowney
Copy link
Contributor Author

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

@patdowney patdowney marked this pull request as ready for review May 13, 2025 21:03
@patdowney
Copy link
Contributor Author

Hi folks, any appetite for this change?

Copy link
Member

@Juneezee Juneezee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a nice feature to have

@Juneezee Juneezee requested a review from dearchap July 16, 2025 10:26
@Juneezee Juneezee merged commit b88b11d into urfave:main Jul 18, 2025
9 checks passed
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

Successfully merging this pull request may close these issues.

3 participants