mirror of https://github.com/docker/cli.git
Merge pull request #1251 from silvin-lubecki/fix-stack-help-command
Fix help message flags on docker stack commands and sub-commands
This commit is contained in:
commit
4fbb009d39
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
|
cliconfig "github.com/docker/cli/cli/config"
|
||||||
"github.com/docker/cli/cli/config/configfile"
|
"github.com/docker/cli/cli/config/configfile"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
@ -27,7 +28,11 @@ func NewStackCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Short: "Manage Docker stacks",
|
Short: "Manage Docker stacks",
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
orchestrator, err := getOrchestrator(dockerCli.ConfigFile(), cmd, dockerCli.Err())
|
configFile := dockerCli.ConfigFile()
|
||||||
|
if configFile == nil {
|
||||||
|
configFile = cliconfig.LoadDefaultConfigFile(dockerCli.Err())
|
||||||
|
}
|
||||||
|
orchestrator, err := getOrchestrator(configFile, cmd, dockerCli.Err())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -42,9 +47,13 @@ func NewStackCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
defaultHelpFunc := cmd.HelpFunc()
|
defaultHelpFunc := cmd.HelpFunc()
|
||||||
cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
|
cmd.SetHelpFunc(func(c *cobra.Command, args []string) {
|
||||||
hideOrchestrationFlags(cmd, opts.orchestrator)
|
if err := cmd.PersistentPreRunE(c, args); err != nil {
|
||||||
defaultHelpFunc(cmd, args)
|
fmt.Fprintln(dockerCli.Err(), err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hideOrchestrationFlags(c, opts.orchestrator)
|
||||||
|
defaultHelpFunc(c, args)
|
||||||
})
|
})
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
newDeployCommand(dockerCli, &opts),
|
newDeployCommand(dockerCli, &opts),
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package stack
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gotest.tools/golden"
|
||||||
|
"gotest.tools/icmd"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStackDeployHelp(t *testing.T) {
|
||||||
|
t.Run("Swarm", func(t *testing.T) {
|
||||||
|
testStackDeployHelp(t, "swarm")
|
||||||
|
})
|
||||||
|
t.Run("Kubernetes", func(t *testing.T) {
|
||||||
|
testStackDeployHelp(t, "kubernetes")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func testStackDeployHelp(t *testing.T, orchestrator string) {
|
||||||
|
result := icmd.RunCommand("docker", "stack", "deploy", "--orchestrator", orchestrator, "--help")
|
||||||
|
result.Assert(t, icmd.Success)
|
||||||
|
golden.Assert(t, result.Stdout(), fmt.Sprintf("stack-deploy-help-%s.golden", orchestrator))
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
Usage: docker stack deploy [OPTIONS] STACK
|
||||||
|
|
||||||
|
Deploy a new stack or update an existing stack
|
||||||
|
|
||||||
|
Aliases:
|
||||||
|
deploy, up
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-c, --compose-file strings Path to a Compose file, or "-" to read
|
||||||
|
from stdin
|
||||||
|
--kubeconfig string Kubernetes config file
|
||||||
|
--namespace string Kubernetes namespace to use
|
||||||
|
--orchestrator string Orchestrator to use (swarm|kubernetes|all)
|
|
@ -0,0 +1,19 @@
|
||||||
|
|
||||||
|
Usage: docker stack deploy [OPTIONS] STACK
|
||||||
|
|
||||||
|
Deploy a new stack or update an existing stack
|
||||||
|
|
||||||
|
Aliases:
|
||||||
|
deploy, up
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--bundle-file string Path to a Distributed Application Bundle file
|
||||||
|
-c, --compose-file strings Path to a Compose file, or "-" to read
|
||||||
|
from stdin
|
||||||
|
--orchestrator string Orchestrator to use (swarm|kubernetes|all)
|
||||||
|
--prune Prune services that are no longer referenced
|
||||||
|
--resolve-image string Query the registry to resolve image digest
|
||||||
|
and supported platforms
|
||||||
|
("always"|"changed"|"never") (default "always")
|
||||||
|
--with-registry-auth Send registry authentication details to
|
||||||
|
Swarm agents
|
Loading…
Reference in New Issue