From fce8d8aeb08dc6afe413cc0af67a7fbb3cffec4c Mon Sep 17 00:00:00 2001 From: Skeet WU Date: Tue, 27 Sep 2022 18:27:48 +0800 Subject: [PATCH] Expose ValidateRequiredFlags and ValidateFlagGroups (#1760) --- command.go | 7 ++++--- flag_groups.go | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/command.go b/command.go index cdfd360f..1867d22c 100644 --- a/command.go +++ b/command.go @@ -862,10 +862,10 @@ func (c *Command) execute(a []string) (err error) { c.PreRun(c, argWoFlags) } - if err := c.validateRequiredFlags(); err != nil { + if err := c.ValidateRequiredFlags(); err != nil { return err } - if err := c.validateFlagGroups(); err != nil { + if err := c.ValidateFlagGroups(); err != nil { return err } @@ -1019,7 +1019,8 @@ func (c *Command) ValidateArgs(args []string) error { return c.Args(c, args) } -func (c *Command) validateRequiredFlags() error { +// ValidateRequiredFlags validates all required flags are present and returns an error otherwise +func (c *Command) ValidateRequiredFlags() error { if c.DisableFlagParsing { return nil } diff --git a/flag_groups.go b/flag_groups.go index b09236fa..9c377aaf 100644 --- a/flag_groups.go +++ b/flag_groups.go @@ -59,9 +59,9 @@ func (c *Command) MarkFlagsMutuallyExclusive(flagNames ...string) { } } -// validateFlagGroups validates the mutuallyExclusive/requiredAsGroup logic and returns the +// ValidateFlagGroups validates the mutuallyExclusive/requiredAsGroup logic and returns the // first error encountered. -func (c *Command) validateFlagGroups() error { +func (c *Command) ValidateFlagGroups() error { if c.DisableFlagParsing { return nil }