inspect: add shell-completion for "--type" flag

With this patch:

    docker inspect --type <TAB>
    config     image    node    secret   task
    container  network  plugin  service  volume

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2025-05-06 14:27:53 +02:00
parent 877ea1ce35
commit 7203340f53
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C

View File

@ -39,6 +39,19 @@ const (
typeVolume objectType = "volume"
)
var allTypes = []objectType{
typeConfig,
typeContainer,
typeImage,
typeNetwork,
typeNode,
typePlugin,
typeSecret,
typeService,
typeTask,
typeVolume,
}
type inspectOptions struct {
format string
objectType objectType
@ -67,6 +80,7 @@ func NewInspectCommand(dockerCli command.Cli) *cobra.Command {
flags.StringVar(&opts.objectType, "type", "", "Return JSON for specified type")
flags.BoolVarP(&opts.size, "size", "s", false, "Display total file sizes if the type is container")
_ = cmd.RegisterFlagCompletionFunc("type", completion.FromList(allTypes...))
flags.VisitAll(func(flag *pflag.Flag) {
// Set a default completion function if none was set. We don't look
// up if it does already have one set, because Cobra does this for