cli/command/completion: add FromList utility
It's an alias for cobra.FixedCompletions but takes a variadic list of strings, so that it's not needed to construct an array for this. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/docker/cli/cli/command/completion"
|
||||
"github.com/docker/cli/cli/context/store"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@ -19,13 +20,7 @@ func registerCompletionFuncForGlobalFlags(contextStore store.Store, cmd *cobra.C
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = cmd.RegisterFlagCompletionFunc(
|
||||
"log-level",
|
||||
func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
values := []string{"debug", "info", "warn", "error", "fatal"}
|
||||
return values, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
)
|
||||
err = cmd.RegisterFlagCompletionFunc("log-level", completion.FromList("debug", "info", "warn", "error", "fatal"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user