Skip to content

Commit 877ea1c

Browse files
committed
inspect: disable default (file) completion
Before this patch, flags and arguments would complete using filenames from the current directory; docker inspect --type <TAB> AUTHORS CONTRIBUTING.md docs/ Makefile SECURITY.md ... docker inspect <TAB> With this patch, no completion is provided; docker inspect --type <TAB> # no results docker inspect <TAB> # no results Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent f61e2bb commit 877ea1c

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

cli/command/system/inspect.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/docker/cli/cli"
1313
"github.com/docker/cli/cli/command"
14+
"github.com/docker/cli/cli/command/completion"
1415
"github.com/docker/cli/cli/command/inspect"
1516
flagsHelper "github.com/docker/cli/cli/flags"
1617
"github.com/docker/docker/api/types"
@@ -20,6 +21,7 @@ import (
2021
"github.com/docker/docker/errdefs"
2122
"github.com/pkg/errors"
2223
"github.com/spf13/cobra"
24+
"github.com/spf13/pflag"
2325
)
2426

2527
type objectType = string
@@ -56,13 +58,21 @@ func NewInspectCommand(dockerCli command.Cli) *cobra.Command {
5658
opts.ids = args
5759
return runInspect(cmd.Context(), dockerCli, opts)
5860
},
61+
// TODO(thaJeztah): should we consider adding completion for common object-types? (images, containers?)
62+
ValidArgsFunction: completion.NoComplete,
5963
}
6064

6165
flags := cmd.Flags()
6266
flags.StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp)
6367
flags.StringVar(&opts.objectType, "type", "", "Return JSON for specified type")
6468
flags.BoolVarP(&opts.size, "size", "s", false, "Display total file sizes if the type is container")
6569

70+
flags.VisitAll(func(flag *pflag.Flag) {
71+
// Set a default completion function if none was set. We don't look
72+
// up if it does already have one set, because Cobra does this for
73+
// us, and returns an error (which we ignore for this reason).
74+
_ = cmd.RegisterFlagCompletionFunc(flag.Name, completion.NoComplete)
75+
})
6676
return cmd
6777
}
6878

0 commit comments

Comments
 (0)