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

View File

@ -20,6 +20,7 @@ import (
dopts "github.com/docker/docker/opts" dopts "github.com/docker/docker/opts"
"github.com/docker/go-connections/sockets" "github.com/docker/go-connections/sockets"
"github.com/docker/go-connections/tlsconfig" "github.com/docker/go-connections/tlsconfig"
"github.com/spf13/cobra"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -73,6 +74,13 @@ func (cli *DockerCli) In() *InStream {
return cli.in 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 // ConfigFile returns the ConfigFile
func (cli *DockerCli) ConfigFile() *configfile.ConfigFile { func (cli *DockerCli) ConfigFile() *configfile.ConfigFile {
return cli.configFile return cli.configFile

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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