Use spf13/cobra for docker search

- Move image command search to `api/client/image/search.go`
- Use cobra :)

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2016-06-03 19:50:01 +02:00
parent 82c85e1e83
commit bbefa88a8c
3 changed files with 18 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/docker/docker/api/client"
"github.com/docker/docker/api/client/image"
"github.com/docker/docker/api/client/volume"
"github.com/docker/docker/cli"
cliflags "github.com/docker/docker/cli/flags"
@ -34,6 +35,7 @@ func NewCobraAdaptor(clientFlags *cliflags.ClientFlags) CobraAdaptor {
rootCmd.SetOutput(stdout)
rootCmd.AddCommand(
volume.NewVolumeCommand(dockerCli),
image.NewSearchCommand(dockerCli),
)
rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage")

View File

@ -40,3 +40,19 @@ func RequiresMinArgs(min int) cobra.PositionalArgs {
)
}
}
// ExactArgs returns an error if there is not the exact number of args
func ExactArgs(number int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
if len(args) == number {
return nil
}
return fmt.Errorf(
"\"%s\" requires exactly %d argument(s).\n\nUsage: %s\n\n%s",
cmd.CommandPath(),
number,
cmd.UseLine(),
cmd.Short,
)
}
}

View File

@ -39,7 +39,6 @@ var DockerCommandUsage = []Command{
{"rmi", "Remove one or more images"},
{"run", "Run a command in a new container"},
{"save", "Save one or more images to a tar archive"},
{"search", "Search the Docker Hub for images"},
{"start", "Start one or more stopped containers"},
{"stats", "Display a live stream of container(s) resource usage statistics"},
{"stop", "Stop a running container"},