From befa5b2bde98119f0ad751793269c13f5a33fab4 Mon Sep 17 00:00:00 2001 From: Igor Mosyagin <408698+cra@users.noreply.github.com> Date: Sat, 17 Oct 2026 20:08:38 +0200 Subject: [PATCH] fix file completion for image load input Signed-off-by: Igor Mosyagin <408698+cra@users.noreply.github.com> --- cli/command/image/load.go | 1 + cli/command/image/load_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/cli/command/image/load.go b/cli/command/image/load.go index 4fc939466189..e5487bba9c78 100644 --- a/cli/command/image/load.go +++ b/cli/command/image/load.go @@ -49,6 +49,7 @@ func newLoadCommand(dockerCLI command.Cli) *cobra.Command { _ = flags.SetAnnotation("platform", "version", []string{"1.48"}) _ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms()) + _ = cmd.RegisterFlagCompletionFunc("input", completion.FileNames()) return cmd } diff --git a/cli/command/image/load_test.go b/cli/command/image/load_test.go index 9ca0f321d5cf..90772e89dede 100644 --- a/cli/command/image/load_test.go +++ b/cli/command/image/load_test.go @@ -1,6 +1,7 @@ package image import ( + "bytes" "errors" "fmt" "io" @@ -9,6 +10,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/moby/moby/client" + "github.com/spf13/cobra" "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -147,3 +149,25 @@ func TestNewLoadCommandSuccess(t *testing.T) { }) } } + +func TestNewLoadCommandCompletion(t *testing.T) { + for _, args := range [][]string{ + {"-i", ""}, + {"--input", ""}, + {"--input=ar"}, + } { + t.Run(strings.Join(args, " "), func(t *testing.T) { + root := &cobra.Command{Use: "docker"} + root.CompletionOptions.SetDefaultShellCompDirective(cobra.ShellCompDirectiveNoFileComp) + root.AddCommand(newLoadCommand(test.NewFakeCli(&fakeClient{}))) + + var stdout bytes.Buffer + root.SetOut(&stdout) + root.SetErr(io.Discard) + root.SetArgs(append([]string{"__complete", "load"}, args...)) + + assert.NilError(t, root.Execute()) + assert.Equal(t, stdout.String(), ":0\n") + }) + } +}