Merge pull request #23286 from yongtang/23211-spf13-cobra-port

Use spf13/cobra for docker port
This commit is contained in:
Vincent Demeester 2016-06-06 18:55:37 +02:00
commit 2002063bf2
3 changed files with 19 additions and 1 deletions

View File

@ -38,6 +38,7 @@ func NewCobraAdaptor(clientFlags *cliflags.ClientFlags) CobraAdaptor {
container.NewDiffCommand(dockerCli), container.NewDiffCommand(dockerCli),
container.NewExportCommand(dockerCli), container.NewExportCommand(dockerCli),
container.NewLogsCommand(dockerCli), container.NewLogsCommand(dockerCli),
container.NewPortCommand(dockerCli),
container.NewRunCommand(dockerCli), container.NewRunCommand(dockerCli),
container.NewStartCommand(dockerCli), container.NewStartCommand(dockerCli),
container.NewStopCommand(dockerCli), container.NewStopCommand(dockerCli),

View File

@ -43,6 +43,24 @@ func RequiresMinArgs(min int) cobra.PositionalArgs {
} }
} }
// RequiresMinMaxArgs returns an error if there is not at least min args and at most max args
func RequiresMinMaxArgs(min int, max int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
if len(args) >= min && len(args) <= max {
return nil
}
return fmt.Errorf(
"\"%s\" requires at least %d and at most %d argument(s).\nSee '%s --help'.\n\nUsage: %s\n\n%s",
cmd.CommandPath(),
min,
max,
cmd.CommandPath(),
cmd.UseLine(),
cmd.Short,
)
}
}
// ExactArgs returns an error if there is not the exact number of args // ExactArgs returns an error if there is not the exact number of args
func ExactArgs(number int) cobra.PositionalArgs { func ExactArgs(number int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error {

View File

@ -24,7 +24,6 @@ var DockerCommandUsage = []Command{
{"login", "Log in to a Docker registry"}, {"login", "Log in to a Docker registry"},
{"logout", "Log out from a Docker registry"}, {"logout", "Log out from a Docker registry"},
{"pause", "Pause all processes within a container"}, {"pause", "Pause all processes within a container"},
{"port", "List port mappings or a specific mapping for the CONTAINER"},
{"ps", "List containers"}, {"ps", "List containers"},
{"pull", "Pull an image or a repository from a registry"}, {"pull", "Pull an image or a repository from a registry"},
{"push", "Push an image or a repository to a registry"}, {"push", "Push an image or a repository to a registry"},