Skip to content

Commit c3ceba2

Browse files
authored
Merge pull request #6447 from thaJeztah/default_completion
cli: disable file-completion by default
2 parents e78f169 + 47b1715 commit c3ceba2

File tree

15 files changed

+12
-88
lines changed

15 files changed

+12
-88
lines changed

cli-plugins/plugin/plugin.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ func newPluginCommand(dockerCli *command.DockerCli, plugin *cobra.Command, meta
164164
DisableDescriptions: os.Getenv("DOCKER_CLI_DISABLE_COMPLETION_DESCRIPTION") != "",
165165
},
166166
}
167+
168+
// Disable file-completion by default. Most commands and flags should not
169+
// complete with filenames.
170+
cmd.CompletionOptions.SetDefaultShellCompDirective(cobra.ShellCompDirectiveNoFileComp)
171+
167172
opts, _ := cli.SetupPluginRootCommand(cmd)
168173

169174
cmd.SetIn(dockerCli.In())

cli/command/container/create.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
9595

9696
addCompletions(cmd, dockerCLI)
9797

98-
flags.VisitAll(func(flag *pflag.Flag) {
99-
// Set a default completion function if none was set. We don't look
100-
// up if it does already have one set, because Cobra does this for
101-
// us, and returns an error (which we ignore for this reason).
102-
_ = cmd.RegisterFlagCompletionFunc(flag.Name, cobra.NoFileCompletions)
103-
})
104-
10598
return cmd
10699
}
107100

cli/command/container/run.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,6 @@ func newRunCommand(dockerCLI command.Cli) *cobra.Command {
7676
_ = cmd.RegisterFlagCompletionFunc("detach-keys", completeDetachKeys)
7777
addCompletions(cmd, dockerCLI)
7878

79-
flags.VisitAll(func(flag *pflag.Flag) {
80-
// Set a default completion function if none was set. We don't look
81-
// up if it does already have one set, because Cobra does this for
82-
// us, and returns an error (which we ignore for this reason).
83-
_ = cmd.RegisterFlagCompletionFunc(flag.Name, cobra.NoFileCompletions)
84-
})
85-
8679
return cmd
8780
}
8881

cli/command/node/list.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/moby/moby/api/types/system"
1414
"github.com/moby/moby/client"
1515
"github.com/spf13/cobra"
16-
"github.com/spf13/pflag"
1716
)
1817

1918
type listOptions struct {
@@ -41,12 +40,6 @@ func newListCommand(dockerCLI command.Cli) *cobra.Command {
4140
flags.StringVar(&options.format, "format", "", flagsHelper.FormatHelp)
4241
flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
4342

44-
flags.VisitAll(func(flag *pflag.Flag) {
45-
// Set a default completion function if none was set. We don't look
46-
// up if it does already have one set, because Cobra does this for
47-
// us, and returns an error (which we ignore for this reason).
48-
_ = cmd.RegisterFlagCompletionFunc(flag.Name, cobra.NoFileCompletions)
49-
})
5043
return cmd
5144
}
5245

cli/command/node/ps.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/moby/moby/api/types/swarm"
1313
"github.com/moby/moby/client"
1414
"github.com/spf13/cobra"
15-
"github.com/spf13/pflag"
1615
)
1716

1817
type psOptions struct {
@@ -50,12 +49,6 @@ func newPsCommand(dockerCLI command.Cli) *cobra.Command {
5049
flags.StringVar(&options.format, "format", "", "Pretty-print tasks using a Go template")
5150
flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display task IDs")
5251

53-
flags.VisitAll(func(flag *pflag.Flag) {
54-
// Set a default completion function if none was set. We don't look
55-
// up if it does already have one set, because Cobra does this for
56-
// us, and returns an error (which we ignore for this reason).
57-
_ = cmd.RegisterFlagCompletionFunc(flag.Name, cobra.NoFileCompletions)
58-
})
5952
return cmd
6053
}
6154

cli/command/node/update.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ func newUpdateCommand(dockerCLI command.Cli) *cobra.Command {
4040

4141
_ = cmd.RegisterFlagCompletionFunc(flagRole, completion.FromList("worker", "manager"))
4242
_ = cmd.RegisterFlagCompletionFunc(flagAvailability, completion.FromList("active", "pause", "drain"))
43-
flags.VisitAll(func(flag *pflag.Flag) {
44-
// Set a default completion function if none was set. We don't look
45-
// up if it does already have one set, because Cobra does this for
46-
// us, and returns an error (which we ignore for this reason).
47-
_ = cmd.RegisterFlagCompletionFunc(flag.Name, cobra.NoFileCompletions)
48-
})
43+
4944
return cmd
5045
}
5146

cli/command/service/create.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,6 @@ func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
9191
_ = cmd.RegisterFlagCompletionFunc(flagUpdateOrder, completion.FromList("start-first", "stop-first"))
9292
_ = cmd.RegisterFlagCompletionFunc(flagUpdateFailureAction, completion.FromList("pause", "continue", "rollback"))
9393

94-
flags.VisitAll(func(flag *pflag.Flag) {
95-
// Set a default completion function if none was set. We don't look
96-
// up if it does already have one set, because Cobra does this for
97-
// us, and returns an error (which we ignore for this reason).
98-
_ = cmd.RegisterFlagCompletionFunc(flag.Name, cobra.NoFileCompletions)
99-
})
10094
return cmd
10195
}
10296

cli/command/service/inspect.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
flagsHelper "github.com/docker/cli/cli/flags"
1717
"github.com/moby/moby/client"
1818
"github.com/spf13/cobra"
19-
"github.com/spf13/pflag"
2019
)
2120

2221
type inspectOptions struct {
@@ -48,12 +47,6 @@ func newInspectCommand(dockerCLI command.Cli) *cobra.Command {
4847
flags.StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp)
4948
flags.BoolVar(&opts.pretty, "pretty", false, "Print the information in a human friendly format")
5049

51-
flags.VisitAll(func(flag *pflag.Flag) {
52-
// Set a default completion function if none was set. We don't look
53-
// up if it does already have one set, because Cobra does this for
54-
// us, and returns an error (which we ignore for this reason).
55-
_ = cmd.RegisterFlagCompletionFunc(flag.Name, cobra.NoFileCompletions)
56-
})
5750
return cmd
5851
}
5952

cli/command/service/list.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/moby/moby/api/types/swarm"
1313
"github.com/moby/moby/client"
1414
"github.com/spf13/cobra"
15-
"github.com/spf13/pflag"
1615
)
1716

1817
type listOptions struct {
@@ -41,12 +40,6 @@ func newListCommand(dockerCLI command.Cli) *cobra.Command {
4140
flags.StringVar(&options.format, "format", "", flagsHelper.FormatHelp)
4241
flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
4342

44-
flags.VisitAll(func(flag *pflag.Flag) {
45-
// Set a default completion function if none was set. We don't look
46-
// up if it does already have one set, because Cobra does this for
47-
// us, and returns an error (which we ignore for this reason).
48-
_ = cmd.RegisterFlagCompletionFunc(flag.Name, cobra.NoFileCompletions)
49-
})
5043
return cmd
5144
}
5245

cli/command/service/logs.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/moby/moby/api/types/swarm"
2121
"github.com/moby/moby/client"
2222
"github.com/spf13/cobra"
23-
"github.com/spf13/pflag"
2423
)
2524

2625
type logsOptions struct {
@@ -68,12 +67,6 @@ func newLogsCommand(dockerCLI command.Cli) *cobra.Command {
6867
flags.SetAnnotation("details", "version", []string{"1.30"})
6968
flags.StringVarP(&opts.tail, "tail", "n", "all", "Number of lines to show from the end of the logs")
7069

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

0 commit comments

Comments
 (0)