refactor help func in CLI

Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
Victor Vieux 2016-11-17 10:54:10 -08:00
parent 91aed2e673
commit 55908f8a82
13 changed files with 22 additions and 51 deletions

View File

@ -12,11 +12,8 @@ func NewCheckpointCommand(dockerCli *command.DockerCli) *cobra.Command {
Use: "checkpoint",
Short: "Manage checkpoints",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
},
Tags: map[string]string{"experimental": "", "version": "1.25"},
RunE: dockerCli.ShowHelp,
Tags: map[string]string{"experimental": "", "version": "1.25"},
}
cmd.AddCommand(
newCreateCommand(dockerCli),

View File

@ -20,6 +20,7 @@ import (
dopts "github.com/docker/docker/opts"
"github.com/docker/go-connections/sockets"
"github.com/docker/go-connections/tlsconfig"
"github.com/spf13/cobra"
"golang.org/x/net/context"
)
@ -73,6 +74,13 @@ func (cli *DockerCli) In() *InStream {
return cli.in
}
// ShowHelp shows the command help.
func (cli *DockerCli) ShowHelp(cmd *cobra.Command, args []string) error {
cmd.SetOutput(cli.err)
cmd.HelpFunc()(cmd, args)
return nil
}
// ConfigFile returns the ConfigFile
func (cli *DockerCli) ConfigFile() *configfile.ConfigFile {
return cli.configFile

View File

@ -13,10 +13,7 @@ func NewContainerCommand(dockerCli *command.DockerCli) *cobra.Command {
Use: "container",
Short: "Manage containers",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
},
RunE: dockerCli.ShowHelp,
}
cmd.AddCommand(
NewAttachCommand(dockerCli),

View File

@ -13,10 +13,7 @@ func NewImageCommand(dockerCli *command.DockerCli) *cobra.Command {
Use: "image",
Short: "Manage images",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
},
RunE: dockerCli.ShowHelp,
}
cmd.AddCommand(
NewBuildCommand(dockerCli),

View File

@ -13,10 +13,7 @@ func NewNetworkCommand(dockerCli *command.DockerCli) *cobra.Command {
Use: "network",
Short: "Manage networks",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
},
RunE: dockerCli.ShowHelp,
}
cmd.AddCommand(
newConnectCommand(dockerCli),

View File

@ -14,10 +14,7 @@ func NewNodeCommand(dockerCli *command.DockerCli) *cobra.Command {
Use: "node",
Short: "Manage Swarm nodes",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
},
RunE: dockerCli.ShowHelp,
}
cmd.AddCommand(
newDemoteCommand(dockerCli),

View File

@ -12,10 +12,7 @@ func NewPluginCommand(dockerCli *command.DockerCli) *cobra.Command {
Use: "plugin",
Short: "Manage plugins",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
},
RunE: dockerCli.ShowHelp,
}
cmd.AddCommand(

View File

@ -1,8 +1,6 @@
package secret
import (
"fmt"
"github.com/spf13/cobra"
"github.com/docker/docker/cli"
@ -15,9 +13,7 @@ func NewSecretCommand(dockerCli *command.DockerCli) *cobra.Command {
Use: "secret",
Short: "Manage Docker secrets",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString())
},
RunE: dockerCli.ShowHelp,
}
cmd.AddCommand(
newSecretListCommand(dockerCli),

View File

@ -13,10 +13,7 @@ func NewServiceCommand(dockerCli *command.DockerCli) *cobra.Command {
Use: "service",
Short: "Manage services",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
},
RunE: dockerCli.ShowHelp,
}
cmd.AddCommand(
newCreateCommand(dockerCli),

View File

@ -12,11 +12,8 @@ func NewStackCommand(dockerCli *command.DockerCli) *cobra.Command {
Use: "stack",
Short: "Manage Docker stacks",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
},
Tags: map[string]string{"experimental": "", "version": "1.25"},
RunE: dockerCli.ShowHelp,
Tags: map[string]string{"experimental": "", "version": "1.25"},
}
cmd.AddCommand(
newDeployCommand(dockerCli),

View File

@ -13,10 +13,7 @@ func NewSwarmCommand(dockerCli *command.DockerCli) *cobra.Command {
Use: "swarm",
Short: "Manage Swarm",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
},
RunE: dockerCli.ShowHelp,
}
cmd.AddCommand(
newInitCommand(dockerCli),

View File

@ -13,10 +13,7 @@ func NewSystemCommand(dockerCli *command.DockerCli) *cobra.Command {
Use: "system",
Short: "Manage Docker",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
},
RunE: dockerCli.ShowHelp,
}
cmd.AddCommand(
NewEventsCommand(dockerCli),

View File

@ -14,10 +14,7 @@ func NewVolumeCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "Manage volumes",
Long: volumeDescription,
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
},
RunE: dockerCli.ShowHelp,
}
cmd.AddCommand(
newCreateCommand(dockerCli),