2016-04-19 16:59:48 +00:00
|
|
|
package cobraadaptor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/api/client"
|
2016-05-31 23:49:32 +00:00
|
|
|
"github.com/docker/docker/api/client/container"
|
2016-06-03 17:50:01 +00:00
|
|
|
"github.com/docker/docker/api/client/image"
|
2016-06-06 08:28:52 +00:00
|
|
|
"github.com/docker/docker/api/client/network"
|
2016-06-14 02:56:23 +00:00
|
|
|
"github.com/docker/docker/api/client/node"
|
2016-05-16 15:50:55 +00:00
|
|
|
"github.com/docker/docker/api/client/plugin"
|
2016-06-10 10:04:29 +00:00
|
|
|
"github.com/docker/docker/api/client/registry"
|
2016-06-14 02:56:23 +00:00
|
|
|
"github.com/docker/docker/api/client/service"
|
2016-06-08 17:47:46 +00:00
|
|
|
"github.com/docker/docker/api/client/stack"
|
2016-06-14 02:56:23 +00:00
|
|
|
"github.com/docker/docker/api/client/swarm"
|
2016-06-07 02:15:37 +00:00
|
|
|
"github.com/docker/docker/api/client/system"
|
2016-04-19 16:59:48 +00:00
|
|
|
"github.com/docker/docker/api/client/volume"
|
|
|
|
"github.com/docker/docker/cli"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2016-06-22 17:08:04 +00:00
|
|
|
// SetupRootCommand sets default usage, help, and error handling for the
|
|
|
|
// root command.
|
|
|
|
// TODO: move to cmd/docker/docker?
|
|
|
|
// TODO: split into common setup and client setup
|
|
|
|
func SetupRootCommand(rootCmd *cobra.Command, dockerCli *client.DockerCli) {
|
2016-05-16 21:20:29 +00:00
|
|
|
rootCmd.SetUsageTemplate(usageTemplate)
|
|
|
|
rootCmd.SetHelpTemplate(helpTemplate)
|
2016-06-01 05:19:13 +00:00
|
|
|
rootCmd.SetFlagErrorFunc(cli.FlagErrorFunc)
|
2016-06-22 17:08:04 +00:00
|
|
|
rootCmd.SetOutput(dockerCli.Out())
|
2016-04-19 16:59:48 +00:00
|
|
|
rootCmd.AddCommand(
|
2016-06-14 02:56:23 +00:00
|
|
|
node.NewNodeCommand(dockerCli),
|
|
|
|
service.NewServiceCommand(dockerCli),
|
2016-06-08 17:47:46 +00:00
|
|
|
stack.NewStackCommand(dockerCli),
|
|
|
|
stack.NewTopLevelDeployCommand(dockerCli),
|
2016-06-14 02:56:23 +00:00
|
|
|
swarm.NewSwarmCommand(dockerCli),
|
2016-06-05 16:17:39 +00:00
|
|
|
container.NewAttachCommand(dockerCli),
|
2016-06-06 14:57:44 +00:00
|
|
|
container.NewCommitCommand(dockerCli),
|
2016-06-14 15:16:59 +00:00
|
|
|
container.NewCopyCommand(dockerCli),
|
2016-06-01 05:19:13 +00:00
|
|
|
container.NewCreateCommand(dockerCli),
|
2016-06-05 22:13:55 +00:00
|
|
|
container.NewDiffCommand(dockerCli),
|
2016-06-20 13:27:56 +00:00
|
|
|
container.NewExecCommand(dockerCli),
|
2016-06-05 14:42:19 +00:00
|
|
|
container.NewExportCommand(dockerCli),
|
2016-06-06 07:38:20 +00:00
|
|
|
container.NewKillCommand(dockerCli),
|
2016-06-05 22:50:48 +00:00
|
|
|
container.NewLogsCommand(dockerCli),
|
2016-06-05 23:12:59 +00:00
|
|
|
container.NewPauseCommand(dockerCli),
|
2016-06-05 23:48:26 +00:00
|
|
|
container.NewPortCommand(dockerCli),
|
2016-06-08 12:56:44 +00:00
|
|
|
container.NewPsCommand(dockerCli),
|
2016-06-06 02:16:26 +00:00
|
|
|
container.NewRenameCommand(dockerCli),
|
2016-06-06 14:15:46 +00:00
|
|
|
container.NewRestartCommand(dockerCli),
|
2016-06-06 15:32:38 +00:00
|
|
|
container.NewRmCommand(dockerCli),
|
2016-05-31 23:49:32 +00:00
|
|
|
container.NewRunCommand(dockerCli),
|
2016-06-05 15:03:58 +00:00
|
|
|
container.NewStartCommand(dockerCli),
|
2016-06-06 16:47:18 +00:00
|
|
|
container.NewStatsCommand(dockerCli),
|
2016-06-05 17:25:21 +00:00
|
|
|
container.NewStopCommand(dockerCli),
|
2016-06-06 13:38:43 +00:00
|
|
|
container.NewTopCommand(dockerCli),
|
2016-06-05 18:43:07 +00:00
|
|
|
container.NewUnpauseCommand(dockerCli),
|
2016-06-05 20:55:00 +00:00
|
|
|
container.NewUpdateCommand(dockerCli),
|
2016-06-06 00:25:22 +00:00
|
|
|
container.NewWaitCommand(dockerCli),
|
2016-06-07 16:15:44 +00:00
|
|
|
image.NewBuildCommand(dockerCli),
|
2016-06-06 02:54:33 +00:00
|
|
|
image.NewHistoryCommand(dockerCli),
|
2016-06-06 03:55:47 +00:00
|
|
|
image.NewImagesCommand(dockerCli),
|
2016-06-09 15:28:33 +00:00
|
|
|
image.NewLoadCommand(dockerCli),
|
2016-06-05 20:40:35 +00:00
|
|
|
image.NewRemoveCommand(dockerCli),
|
2016-06-09 15:38:20 +00:00
|
|
|
image.NewSaveCommand(dockerCli),
|
2016-06-10 10:07:23 +00:00
|
|
|
image.NewPullCommand(dockerCli),
|
2016-06-10 10:07:28 +00:00
|
|
|
image.NewPushCommand(dockerCli),
|
2016-06-03 17:50:01 +00:00
|
|
|
image.NewSearchCommand(dockerCli),
|
2016-06-06 11:58:23 +00:00
|
|
|
image.NewImportCommand(dockerCli),
|
2016-06-05 18:05:35 +00:00
|
|
|
image.NewTagCommand(dockerCli),
|
2016-06-06 08:28:52 +00:00
|
|
|
network.NewNetworkCommand(dockerCli),
|
2016-06-06 16:47:18 +00:00
|
|
|
system.NewEventsCommand(dockerCli),
|
2016-06-23 15:09:49 +00:00
|
|
|
system.NewInspectCommand(dockerCli),
|
2016-06-10 10:04:29 +00:00
|
|
|
registry.NewLoginCommand(dockerCli),
|
|
|
|
registry.NewLogoutCommand(dockerCli),
|
2016-06-07 02:15:37 +00:00
|
|
|
system.NewVersionCommand(dockerCli),
|
2016-05-31 23:49:32 +00:00
|
|
|
volume.NewVolumeCommand(dockerCli),
|
2016-06-08 21:42:25 +00:00
|
|
|
system.NewInfoCommand(dockerCli),
|
2016-04-19 16:59:48 +00:00
|
|
|
)
|
2016-05-16 15:50:55 +00:00
|
|
|
plugin.NewPluginCommand(rootCmd, dockerCli)
|
2016-05-16 21:20:29 +00:00
|
|
|
|
2016-05-31 21:47:51 +00:00
|
|
|
rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage")
|
|
|
|
rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help")
|
2016-04-19 16:59:48 +00:00
|
|
|
}
|
|
|
|
|
2016-06-09 15:33:28 +00:00
|
|
|
// GetRootCommand returns the root command. Required to generate the man pages
|
|
|
|
// and reference docs from a script outside this package.
|
|
|
|
func (c CobraAdaptor) GetRootCommand() *cobra.Command {
|
|
|
|
return c.rootCmd
|
|
|
|
}
|
|
|
|
|
2016-07-16 14:44:10 +00:00
|
|
|
var usageTemplate = `Usage: {{if not .HasSubCommands}}{{.UseLine}}{{end}}{{if .HasSubCommands}}{{ .CommandPath}} COMMAND{{end}}
|
2016-05-16 21:20:29 +00:00
|
|
|
|
2016-06-09 15:33:28 +00:00
|
|
|
{{ .Short | trim }}{{if gt .Aliases 0}}
|
2016-04-19 16:59:48 +00:00
|
|
|
|
|
|
|
Aliases:
|
2016-05-16 21:20:29 +00:00
|
|
|
{{.NameAndAliases}}{{end}}{{if .HasExample}}
|
2016-04-19 16:59:48 +00:00
|
|
|
|
|
|
|
Examples:
|
2016-05-16 21:20:29 +00:00
|
|
|
{{ .Example }}{{end}}{{if .HasFlags}}
|
2016-04-19 16:59:48 +00:00
|
|
|
|
|
|
|
Options:
|
2016-05-16 21:20:29 +00:00
|
|
|
{{.Flags.FlagUsages | trimRightSpace}}{{end}}{{ if .HasAvailableSubCommands}}
|
2016-04-19 16:59:48 +00:00
|
|
|
|
|
|
|
Commands:{{range .Commands}}{{if .IsAvailableCommand}}
|
|
|
|
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasSubCommands }}
|
|
|
|
|
|
|
|
Run '{{.CommandPath}} COMMAND --help' for more information on a command.{{end}}
|
|
|
|
`
|
2016-05-16 21:20:29 +00:00
|
|
|
|
|
|
|
var helpTemplate = `
|
|
|
|
{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
|