Files
docker-cli/cli/command/stack/cmd.go
Sebastiaan van Stijn 6647e229be cli/command/stack: move GetStacks and StackWrite internal
These were deprecated in 036d3a6bab and
30774ed1f2, and were originally in the
cli/command/stack package, but moved for the (now deprecated) Compose
on Kubernetes feature in 4d947de292.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-01 09:40:44 +02:00

66 lines
1.8 KiB
Go

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",
},
}
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
}
}