Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion cli/command/config/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions cli/command/config/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
4 changes: 1 addition & 3 deletions cli/command/config/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/secret/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 17 additions & 0 deletions cli/command/secret/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions cli/command/secret/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
4 changes: 1 addition & 3 deletions cli/command/secret/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
4 changes: 1 addition & 3 deletions cli/command/secret/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
4 changes: 1 addition & 3 deletions cli/command/stack/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
4 changes: 1 addition & 3 deletions cli/command/stack/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions cli/command/stack/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
4 changes: 1 addition & 3 deletions cli/command/stack/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading