const requiredAsGroupAnnotation … const oneRequiredAnnotation … const mutuallyExclusiveAnnotation … // MarkFlagsRequiredTogether marks the given flags with annotations so that Cobra errors // if the command is invoked with a subset (but not all) of the given flags. func (c *Command) MarkFlagsRequiredTogether(flagNames ...string) { … } // MarkFlagsOneRequired marks the given flags with annotations so that Cobra errors // if the command is invoked without at least one flag from the given set of flags. func (c *Command) MarkFlagsOneRequired(flagNames ...string) { … } // MarkFlagsMutuallyExclusive marks the given flags with annotations so that Cobra errors // if the command is invoked with more than one flag from the given set of flags. func (c *Command) MarkFlagsMutuallyExclusive(flagNames ...string) { … } // ValidateFlagGroups validates the mutuallyExclusive/oneRequired/requiredAsGroup logic and returns the // first error encountered. func (c *Command) ValidateFlagGroups() error { … } func hasAllFlags(fs *flag.FlagSet, flagnames ...string) bool { … } func processFlagForGroupAnnotation(flags *flag.FlagSet, pflag *flag.Flag, annotation string, groupStatus map[string]map[string]bool) { … } func validateRequiredFlagGroups(data map[string]map[string]bool) error { … } func validateOneRequiredFlagGroups(data map[string]map[string]bool) error { … } func validateExclusiveFlagGroups(data map[string]map[string]bool) error { … } func sortedKeys(m map[string]map[string]bool) []string { … } // enforceFlagGroupsForCompletion will do the following: // - when a flag in a group is present, other flags in the group will be marked required // - when none of the flags in a one-required group are present, all flags in the group will be marked required // - when a flag in a mutually exclusive group is present, other flags in the group will be marked as hidden // This allows the standard completion logic to behave appropriately for flag groups func (c *Command) enforceFlagGroupsForCompletion() { … }