From fcd9f9f7bd623d0d8a6ee823e463786ed408faa1 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Sun, 5 Jun 2016 20:55:47 -0700 Subject: [PATCH] Use spf13/cobra for docker images This fix is part of the effort to convert commands to spf13/cobra #23211. Thif fix coverted command `docker images` to use spf13/cobra NOTE: As part of this fix, a new function `RequiresMaxArgs()` has been defined in `cli/required.go`. This func returns an error if there is not at most max args Signed-off-by: Yong Tang --- cobraadaptor/adaptor.go | 1 + required.go | 17 +++++++++++++++++ usage.go | 1 - 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cobraadaptor/adaptor.go b/cobraadaptor/adaptor.go index 0d536f0608..4f1f77ca00 100644 --- a/cobraadaptor/adaptor.go +++ b/cobraadaptor/adaptor.go @@ -51,6 +51,7 @@ func NewCobraAdaptor(clientFlags *cliflags.ClientFlags) CobraAdaptor { container.NewUnpauseCommand(dockerCli), container.NewWaitCommand(dockerCli), image.NewHistoryCommand(dockerCli), + image.NewImagesCommand(dockerCli), image.NewRemoveCommand(dockerCli), image.NewSearchCommand(dockerCli), image.NewImportCommand(dockerCli), diff --git a/required.go b/required.go index 0cf35b3d68..0c08e64f1a 100644 --- a/required.go +++ b/required.go @@ -43,6 +43,23 @@ func RequiresMinArgs(min int) cobra.PositionalArgs { } } +// RequiresMaxArgs returns an error if there is not at most max args +func RequiresMaxArgs(max int) cobra.PositionalArgs { + return func(cmd *cobra.Command, args []string) error { + if len(args) <= max { + return nil + } + return fmt.Errorf( + "\"%s\" requires at most %d argument(s).\nSee '%s --help'.\n\nUsage: %s\n\n%s", + cmd.CommandPath(), + max, + cmd.CommandPath(), + cmd.UseLine(), + cmd.Short, + ) + } +} + // 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 { diff --git a/usage.go b/usage.go index baf4948931..a144df1af8 100644 --- a/usage.go +++ b/usage.go @@ -13,7 +13,6 @@ var DockerCommandUsage = []Command{ {"cp", "Copy files/folders between a container and the local filesystem"}, {"events", "Get real time events from the server"}, {"exec", "Run a command in a running container"}, - {"images", "List images"}, {"info", "Display system-wide information"}, {"inspect", "Return low-level information on a container or image"}, {"load", "Load an image from a tar archive or STDIN"},