diff options
author | openshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com> | 2022-06-21 17:37:14 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-21 17:37:14 +0000 |
commit | b8b0fa80454fe0f3bcdab24bbf17cf0b6c2e8661 (patch) | |
tree | b20a2993e7c5cc5015476c65e15edb8b4bccf207 /vendor/github.com/spf13/cobra/command.go | |
parent | 588d8ec371202b5f6101c11f4c3e2952c2843d85 (diff) | |
parent | 050693b2e773e6334dc200fc0c819e3829ac400d (diff) | |
download | podman-b8b0fa80454fe0f3bcdab24bbf17cf0b6c2e8661.tar.gz podman-b8b0fa80454fe0f3bcdab24bbf17cf0b6c2e8661.tar.bz2 podman-b8b0fa80454fe0f3bcdab24bbf17cf0b6c2e8661.zip |
Merge pull request #14683 from Luap99/bump-cobra
bump github.com/spf13/cobra from 1.4.0 to 1.5.0
Diffstat (limited to 'vendor/github.com/spf13/cobra/command.go')
-rw-r--r-- | vendor/github.com/spf13/cobra/command.go | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/vendor/github.com/spf13/cobra/command.go b/vendor/github.com/spf13/cobra/command.go index 2cc18891d..675bb1340 100644 --- a/vendor/github.com/spf13/cobra/command.go +++ b/vendor/github.com/spf13/cobra/command.go @@ -18,6 +18,7 @@ package cobra import ( "bytes" "context" + "errors" "fmt" "io" "os" @@ -166,7 +167,7 @@ type Command struct { // errWriter is a writer defined by the user that replaces stderr errWriter io.Writer - //FParseErrWhitelist flag parse errors to be ignored + // FParseErrWhitelist flag parse errors to be ignored FParseErrWhitelist FParseErrWhitelist // CompletionOptions is a set of options to control the handling of shell completion @@ -224,12 +225,23 @@ type Command struct { SuggestionsMinimumDistance int } -// Context returns underlying command context. If command wasn't -// executed with ExecuteContext Context returns Background context. +// Context returns underlying command context. If command was executed +// with ExecuteContext or the context was set with SetContext, the +// previously set context will be returned. Otherwise, nil is returned. +// +// Notice that a call to Execute and ExecuteC will replace a nil context of +// a command with a context.Background, so a background context will be +// returned by Context after one of these functions has been called. func (c *Command) Context() context.Context { return c.ctx } +// SetContext sets context for the command. It is set to context.Background by default and will be overwritten by +// Command.ExecuteContext or Command.ExecuteContextC +func (c *Command) SetContext(ctx context.Context) { + c.ctx = ctx +} + // SetArgs sets arguments for the command. It is set to os.Args[1:] by default, if desired, can be overridden // particularly useful when testing. func (c *Command) SetArgs(a []string) { @@ -852,6 +864,10 @@ func (c *Command) execute(a []string) (err error) { if err := c.validateRequiredFlags(); err != nil { return err } + if err := c.validateFlagGroups(); err != nil { + return err + } + if c.RunE != nil { if err := c.RunE(c, argWoFlags); err != nil { return err @@ -975,7 +991,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) { if err != nil { // Always show help if requested, even if SilenceErrors is in // effect - if err == flag.ErrHelp { + if errors.Is(err, flag.ErrHelp) { cmd.HelpFunc()(cmd, args) return cmd, nil } @@ -997,7 +1013,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) { func (c *Command) ValidateArgs(args []string) error { if c.Args == nil { - return nil + return ArbitraryArgs(c, args) } return c.Args(c, args) } |