Closed vague2k closed 1 month ago
I think you are looking for flag groups: https://github.com/spf13/cobra/blob/main/site/content/user_guide.md#flag-groups
I think you are looking for flag groups: https://github.com/spf13/cobra/blob/main/site/content/user_guide.md#flag-groups
the difference between the builtin flag groups and what im describing is that (referring again to my example) if you use
--24H
you ARE REQUIRED to include --createdAt
but if you use --createdAt
by itself you ARE NOT REQUIRED to include --24H
.
I guess you to give it a name i'd call what i'm describing as a one-way MarkFlagsRequiredTogether
Here's an example, assume you have some output where an item is printed and the item has more info that you would like to show when the proper flags are present.
In this example a flag called
createdAt
can be used to show the timestamp of when the item was created. But what if you wanted to show a specific format for that timestamp... you could do something like...Is there a way that to make it such that (referring to this example)
--24H
depends on--createdAt
?I've dug a bit to see if anyone had a similar question or solution but couldn't find anything note worthy.
If there is a solution and it seems too hacky or janky, I also think it would be cool have a utility method such as
cmd.MarkFlagsAsDependent()
if it's worth writing