summaryrefslogtreecommitdiff
path: root/vendor/github.com/spf13/cobra/command.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2021-07-02 11:37:41 +0200
committerValentin Rothberg <rothberg@redhat.com>2021-07-02 11:38:28 +0200
commit7eb9ed975899ffe12fb82066aebf652444205e02 (patch)
tree7bcf61f24cab74996f3641c0d6163a0b47979694 /vendor/github.com/spf13/cobra/command.go
parent955c1d2bfeac0c399bbc4d82fd7b72ed4cc868d3 (diff)
downloadpodman-7eb9ed975899ffe12fb82066aebf652444205e02.tar.gz
podman-7eb9ed975899ffe12fb82066aebf652444205e02.tar.bz2
podman-7eb9ed975899ffe12fb82066aebf652444205e02.zip
vendor containers/common@main
Pull in fixes for local image lookups. Fixes: #10835 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/github.com/spf13/cobra/command.go')
-rw-r--r--vendor/github.com/spf13/cobra/command.go33
1 files changed, 25 insertions, 8 deletions
diff --git a/vendor/github.com/spf13/cobra/command.go b/vendor/github.com/spf13/cobra/command.go
index d6732ad11..9f33a461f 100644
--- a/vendor/github.com/spf13/cobra/command.go
+++ b/vendor/github.com/spf13/cobra/command.go
@@ -63,9 +63,9 @@ type Command struct {
// Example is examples of how to use the command.
Example string
- // ValidArgs is list of all valid non-flag arguments that are accepted in bash completions
+ // ValidArgs is list of all valid non-flag arguments that are accepted in shell completions
ValidArgs []string
- // ValidArgsFunction is an optional function that provides valid non-flag arguments for bash completion.
+ // ValidArgsFunction is an optional function that provides valid non-flag arguments for shell completion.
// It is a dynamic version of using ValidArgs.
// Only one of ValidArgs and ValidArgsFunction can be used for a command.
ValidArgsFunction func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective)
@@ -74,11 +74,12 @@ type Command struct {
Args PositionalArgs
// ArgAliases is List of aliases for ValidArgs.
- // These are not suggested to the user in the bash completion,
+ // These are not suggested to the user in the shell completion,
// but accepted if entered manually.
ArgAliases []string
- // BashCompletionFunction is custom functions used by the bash autocompletion generator.
+ // BashCompletionFunction is custom bash functions used by the legacy bash autocompletion generator.
+ // For portability with other shells, it is recommended to instead use ValidArgsFunction
BashCompletionFunction string
// Deprecated defines, if this command is deprecated and should print this string when used.
@@ -141,6 +142,9 @@ type Command struct {
// that we can use on every pflag set and children commands
globNormFunc func(f *flag.FlagSet, name string) flag.NormalizedName
+ //flagCompletionFunctions is map of flag completion functions.
+ flagCompletionFunctions map[*flag.Flag]func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective)
+
// usageFunc is usage func defined by user.
usageFunc func(*Command) error
// usageTemplate is usage template defined by user.
@@ -168,6 +172,9 @@ type Command struct {
//FParseErrWhitelist flag parse errors to be ignored
FParseErrWhitelist FParseErrWhitelist
+ // CompletionOptions is a set of options to control the handling of shell completion
+ CompletionOptions CompletionOptions
+
// commandsAreSorted defines, if command slice are sorted or not.
commandsAreSorted bool
// commandCalledAs is the name or alias value used to call this command.
@@ -884,7 +891,8 @@ func (c *Command) preRun() {
}
// ExecuteContext is the same as Execute(), but sets the ctx on the command.
-// Retrieve ctx by calling cmd.Context() inside your *Run lifecycle functions.
+// Retrieve ctx by calling cmd.Context() inside your *Run lifecycle or ValidArgs
+// functions.
func (c *Command) ExecuteContext(ctx context.Context) error {
c.ctx = ctx
return c.Execute()
@@ -898,6 +906,14 @@ func (c *Command) Execute() error {
return err
}
+// ExecuteContextC is the same as ExecuteC(), but sets the ctx on the command.
+// Retrieve ctx by calling cmd.Context() inside your *Run lifecycle or ValidArgs
+// functions.
+func (c *Command) ExecuteContextC(ctx context.Context) (*Command, error) {
+ c.ctx = ctx
+ return c.ExecuteC()
+}
+
// ExecuteC executes the command.
func (c *Command) ExecuteC() (cmd *Command, err error) {
if c.ctx == nil {
@@ -914,9 +930,10 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
preExecHookFn(c)
}
- // initialize help as the last point possible to allow for user
- // overriding
+ // initialize help at the last point to allow for user overriding
c.InitDefaultHelpCmd()
+ // initialize completion at the last point to allow for user overriding
+ c.initDefaultCompletionCmd()
args := c.args
@@ -925,7 +942,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
args = os.Args[1:]
}
- // initialize the hidden command to be used for bash completion
+ // initialize the hidden command to be used for shell completion
c.initCompleteCmd(args)
var flags []string