Files
docker-cli/cli/command/plugin/completion.go
Sebastiaan van Stijn f81816ef88 vendor: github.com/moby/moby/api, client 0769fe708773 (master)
full diff: 4ca8aedf92...0769fe7087

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-10 19:35:00 +02:00

46 lines
1.1 KiB
Go

package plugin
import (
"github.com/docker/cli/cli/command/completion"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
type pluginState string
const (
stateAny pluginState = ""
stateEnabled pluginState = "enabled"
stateDisabled pluginState = "disabled"
)
// completeNames offers completion for plugin names in the given state.
// The state argument can be one of:
//
// - "all": all plugins
// - "enabled": all enabled plugins
// - "disabled": all disabled plugins
func completeNames(dockerCLI completion.APIClientProvider, state pluginState) cobra.CompletionFunc {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
f := make(client.Filters)
switch state {
case stateEnabled:
f.Add("enabled", "true")
case stateDisabled:
f.Add("enabled", "false")
case stateAny:
// no filter
}
list, err := dockerCLI.Client().PluginList(cmd.Context(), f)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, v := range list {
names = append(names, v.Name)
}
return names, cobra.ShellCompDirectiveNoFileComp
}
}