-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathcmd.go
More file actions
66 lines (61 loc) · 1.82 KB
/
cmd.go
File metadata and controls
66 lines (61 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package stack
import (
"fmt"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/internal/commands"
"github.com/spf13/cobra"
)
func init() {
commands.Register(newStackCommand)
}
// newStackCommand returns a cobra command for `stack` subcommands
func newStackCommand(dockerCLI command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "stack [OPTIONS]",
Short: "Manage Swarm stacks",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCLI.Err()),
Annotations: map[string]string{
"version": "1.25",
"swarm": "manager",
},
DisableFlagsInUseLine: true,
}
defaultHelpFunc := cmd.HelpFunc()
cmd.SetHelpFunc(func(c *cobra.Command, args []string) {
if err := cmd.Root().PersistentPreRunE(c, args); err != nil {
fmt.Fprintln(dockerCLI.Err(), err)
return
}
defaultHelpFunc(c, args)
})
cmd.AddCommand(
newDeployCommand(dockerCLI),
newListCommand(dockerCLI),
newPsCommand(dockerCLI),
newRemoveCommand(dockerCLI),
newServicesCommand(dockerCLI),
newConfigCommand(dockerCLI),
)
flags := cmd.PersistentFlags()
flags.String("orchestrator", "", "Orchestrator to use (swarm|all)")
flags.SetAnnotation("orchestrator", "deprecated", nil)
flags.MarkDeprecated("orchestrator", "option will be ignored")
return cmd
}
// completeNames offers completion for swarm stacks
func completeNames(dockerCLI completion.APIClientProvider) cobra.CompletionFunc {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
list, err := getStacks(cmd.Context(), dockerCLI.Client())
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, stack := range list {
names = append(names, stack.Name)
}
return names, cobra.ShellCompDirectiveNoFileComp
}
}