diff --git a/cli/command/config/create.go b/cli/command/config/create.go index 4b3903d71e..eba5f08e77 100644 --- a/cli/command/config/create.go +++ b/cli/command/config/create.go @@ -36,7 +36,23 @@ func newConfigCreateCommand(dockerCLI command.Cli) *cobra.Command { createOpts.file = args[1] return runCreate(cmd.Context(), dockerCLI, createOpts) }, - ValidArgsFunction: cobra.NoFileCompletions, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + // No completion for the first argument, which is the name for + // the new config, but if a non-empty name is given, we return + // it as completion to allow "tab"-ing to the next completion. + return []string{toComplete}, cobra.ShellCompDirectiveNoFileComp + case 1: + // Second argument is either "-" or a file to load. + // + // TODO(thaJeztah): provide completion for "-". + return nil, cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveDefault + default: + // Command only accepts two arguments. + return nil, cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveNoFileComp + } + }, DisableFlagsInUseLine: true, } flags := cmd.Flags() diff --git a/cli/command/config/inspect.go b/cli/command/config/inspect.go index 3f8362543f..ec59e62977 100644 --- a/cli/command/config/inspect.go +++ b/cli/command/config/inspect.go @@ -32,9 +32,7 @@ func newConfigInspectCommand(dockerCLI command.Cli) *cobra.Command { opts.names = args return runInspect(cmd.Context(), dockerCLI, opts) }, - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completeNames(dockerCLI)(cmd, args, toComplete) - }, + ValidArgsFunction: completeNames(dockerCLI), DisableFlagsInUseLine: true, } diff --git a/cli/command/config/remove.go b/cli/command/config/remove.go index 2f7de31f62..b4e534d3a9 100644 --- a/cli/command/config/remove.go +++ b/cli/command/config/remove.go @@ -19,9 +19,7 @@ func newConfigRemoveCommand(dockerCLI command.Cli) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { return runRemove(cmd.Context(), dockerCLI, args) }, - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completeNames(dockerCLI)(cmd, args, toComplete) - }, + ValidArgsFunction: completeNames(dockerCLI), DisableFlagsInUseLine: true, } } diff --git a/cli/command/secret/cmd.go b/cli/command/secret/cmd.go index 41b2c56f3d..47b0b43866 100644 --- a/cli/command/secret/cmd.go +++ b/cli/command/secret/cmd.go @@ -44,7 +44,7 @@ func completeNames(dockerCLI completion.APIClientProvider) cobra.CompletionFunc } var names []string for _, secret := range list { - names = append(names, secret.ID) + names = append(names, secret.Spec.Name) } return names, cobra.ShellCompDirectiveNoFileComp } diff --git a/cli/command/secret/create.go b/cli/command/secret/create.go index 5efaf717d3..5cb409e4d6 100644 --- a/cli/command/secret/create.go +++ b/cli/command/secret/create.go @@ -38,6 +38,23 @@ func newSecretCreateCommand(dockerCLI command.Cli) *cobra.Command { } return runSecretCreate(cmd.Context(), dockerCLI, options) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + // No completion for the first argument, which is the name for + // the new secret, but if a non-empty name is given, we return + // it as completion to allow "tab"-ing to the next completion. + return []string{toComplete}, cobra.ShellCompDirectiveNoFileComp + case 1: + // Second argument is either "-" or a file to load. + // + // TODO(thaJeztah): provide completion for "-". + return nil, cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveDefault + default: + // Command only accepts two arguments. + return nil, cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveNoFileComp + } + }, DisableFlagsInUseLine: true, } flags := cmd.Flags() diff --git a/cli/command/secret/inspect.go b/cli/command/secret/inspect.go index 518b1f528a..5d054b6f1d 100644 --- a/cli/command/secret/inspect.go +++ b/cli/command/secret/inspect.go @@ -31,9 +31,7 @@ func newSecretInspectCommand(dockerCLI command.Cli) *cobra.Command { opts.names = args return runSecretInspect(cmd.Context(), dockerCLI, opts) }, - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completeNames(dockerCLI)(cmd, args, toComplete) - }, + ValidArgsFunction: completeNames(dockerCLI), DisableFlagsInUseLine: true, } diff --git a/cli/command/secret/ls.go b/cli/command/secret/ls.go index ece13b39c1..21c4954fb1 100644 --- a/cli/command/secret/ls.go +++ b/cli/command/secret/ls.go @@ -31,9 +31,7 @@ func newSecretListCommand(dockerCLI command.Cli) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { return runSecretList(cmd.Context(), dockerCLI, options) }, - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completeNames(dockerCLI)(cmd, args, toComplete) - }, + ValidArgsFunction: cobra.NoFileCompletions, DisableFlagsInUseLine: true, } diff --git a/cli/command/secret/remove.go b/cli/command/secret/remove.go index 7705490295..76e96cb3c6 100644 --- a/cli/command/secret/remove.go +++ b/cli/command/secret/remove.go @@ -26,9 +26,7 @@ func newSecretRemoveCommand(dockerCLI command.Cli) *cobra.Command { } return runRemove(cmd.Context(), dockerCLI, opts) }, - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completeNames(dockerCLI)(cmd, args, toComplete) - }, + ValidArgsFunction: completeNames(dockerCLI), DisableFlagsInUseLine: true, } } diff --git a/cli/command/stack/deploy.go b/cli/command/stack/deploy.go index c7f699b15d..2d3427be8c 100644 --- a/cli/command/stack/deploy.go +++ b/cli/command/stack/deploy.go @@ -45,9 +45,7 @@ func newDeployCommand(dockerCLI command.Cli) *cobra.Command { } return runDeploy(cmd.Context(), dockerCLI, cmd.Flags(), &opts, config) }, - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completeNames(dockerCLI)(cmd, args, toComplete) - }, + ValidArgsFunction: completeNames(dockerCLI), DisableFlagsInUseLine: true, } diff --git a/cli/command/stack/ps.go b/cli/command/stack/ps.go index 1def911561..b86f6486f1 100644 --- a/cli/command/stack/ps.go +++ b/cli/command/stack/ps.go @@ -38,9 +38,7 @@ func newPsCommand(dockerCLI command.Cli) *cobra.Command { } return runPS(cmd.Context(), dockerCLI, opts) }, - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completeNames(dockerCLI)(cmd, args, toComplete) - }, + ValidArgsFunction: completeNames(dockerCLI), DisableFlagsInUseLine: true, } flags := cmd.Flags() diff --git a/cli/command/stack/remove.go b/cli/command/stack/remove.go index 380d423914..c5ef0e2194 100644 --- a/cli/command/stack/remove.go +++ b/cli/command/stack/remove.go @@ -36,9 +36,7 @@ func newRemoveCommand(dockerCLI command.Cli) *cobra.Command { } return runRemove(cmd.Context(), dockerCLI, opts) }, - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completeNames(dockerCLI)(cmd, args, toComplete) - }, + ValidArgsFunction: completeNames(dockerCLI), DisableFlagsInUseLine: true, } diff --git a/cli/command/stack/services.go b/cli/command/stack/services.go index b6f5428fad..ab8c5e0349 100644 --- a/cli/command/stack/services.go +++ b/cli/command/stack/services.go @@ -38,9 +38,7 @@ func newServicesCommand(dockerCLI command.Cli) *cobra.Command { } return runServices(cmd.Context(), dockerCLI, opts) }, - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completeNames(dockerCLI)(cmd, args, toComplete) - }, + ValidArgsFunction: completeNames(dockerCLI), DisableFlagsInUseLine: true, } flags := cmd.Flags()