diff --git a/api_params.go b/api_params.go index 3c53d0f2aa..f666ac2393 100644 --- a/api_params.go +++ b/api_params.go @@ -78,11 +78,6 @@ type APIContainersOld struct { SizeRootFs int64 } -type APISearch struct { - Name string - Description string -} - type APIID struct { ID string `json:"Id"` } diff --git a/commands.go b/commands.go index f7895557df..876f7610c8 100644 --- a/commands.go +++ b/commands.go @@ -1420,8 +1420,10 @@ func (cli *DockerCli) CmdAttach(args ...string) error { } func (cli *DockerCli) CmdSearch(args ...string) error { - cmd := Subcmd("search", "NAME", "Search the docker index for images") + cmd := Subcmd("search", "TERM", "Search the docker index for images") noTrunc := cmd.Bool("notrunc", false, "Don't truncate output") + trusted := cmd.Bool("trusted", false, "Only show trusted builds") + stars := cmd.Int("stars", 0, "Only displays with at least xxx stars") if err := cmd.Parse(args); err != nil { return nil } @@ -1437,27 +1439,32 @@ func (cli *DockerCli) CmdSearch(args ...string) error { return err } - outs := []APISearch{} + outs := []registry.SearchResult{} err = json.Unmarshal(body, &outs) if err != nil { return err } - fmt.Fprintf(cli.out, "Found %d results matching your query (\"%s\")\n", len(outs), cmd.Arg(0)) - w := tabwriter.NewWriter(cli.out, 33, 1, 3, ' ', 0) - fmt.Fprintf(w, "NAME\tDESCRIPTION\n") - _, width := cli.getTtySize() - if width == 0 { - width = 45 - } else { - width = width - 33 //remote the first column - } + w := tabwriter.NewWriter(cli.out, 10, 1, 3, ' ', 0) + fmt.Fprintf(w, "NAME\tDESCRIPTION\tSTARS\tOFFICIAL\tTRUSTED\n") for _, out := range outs { + if (*trusted && !out.IsTrusted) || (*stars > out.StarCount) { + continue + } desc := strings.Replace(out.Description, "\n", " ", -1) desc = strings.Replace(desc, "\r", " ", -1) - if !*noTrunc && len(desc) > width { - desc = utils.Trunc(desc, width-3) + "..." + if !*noTrunc && len(desc) > 45 { + desc = utils.Trunc(desc, 42) + "..." } - fmt.Fprintf(w, "%s\t%s\n", out.Name, desc) + fmt.Fprintf(w, "%s\t%s\t%d\t", out.Name, desc, out.StarCount) + if out.IsOfficial { + fmt.Fprint(w, "[OK]") + + } + fmt.Fprint(w, "\t") + if out.IsTrusted { + fmt.Fprint(w, "[OK]") + } + fmt.Fprint(w, "\n") } w.Flush() return nil diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 5a91ab0f18..8e535285e1 100755 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -426,7 +426,7 @@ _docker_run() _docker_search() { - COMPREPLY=( $( compgen -W "-notrunc" -- "$cur" ) ) + COMPREPLY=( $( compgen -W "-notrunc" "-stars" "-trusted" -- "$cur" ) ) } _docker_start() diff --git a/docs/sources/commandline/cli.rst b/docs/sources/commandline/cli.rst index c85c602117..da0c262c4a 100644 --- a/docs/sources/commandline/cli.rst +++ b/docs/sources/commandline/cli.rst @@ -677,8 +677,11 @@ to the newly created container. Usage: docker search TERM - Searches for the TERM parameter on the Docker index and prints out - a list of repositories that match. + Search the docker index for images + + -notrunc=false: Don't truncate output + -stars=0: Only displays with at least xxx stars + -trusted=false: Only show trusted builds .. _cli_start: diff --git a/registry/registry.go b/registry/registry.go index 9e49f35660..f02e3cf477 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -615,10 +615,18 @@ func (r *Registry) GetAuthConfig(withPasswd bool) *auth.AuthConfig { } } +type SearchResult struct { + StarCount int `json:"star_count"` + IsOfficial bool `json:"is_official"` + Name string `json:"name"` + IsTrusted bool `json:"is_trusted"` + Description string `json:"description"` +} + type SearchResults struct { - Query string `json:"query"` - NumResults int `json:"num_results"` - Results []map[string]string `json:"results"` + Query string `json:"query"` + NumResults int `json:"num_results"` + Results []SearchResult `json:"results"` } type RepositoryData struct { diff --git a/server.go b/server.go index 2748c88b1e..82c9482986 100644 --- a/server.go +++ b/server.go @@ -183,7 +183,7 @@ func (srv *Server) ContainerExport(name string, out io.Writer) error { return fmt.Errorf("No such container: %s", name) } -func (srv *Server) ImagesSearch(term string) ([]APISearch, error) { +func (srv *Server) ImagesSearch(term string) ([]registry.SearchResult, error) { r, err := registry.NewRegistry(srv.runtime.config.Root, nil, srv.HTTPRequestFactory(nil)) if err != nil { return nil, err @@ -192,15 +192,7 @@ func (srv *Server) ImagesSearch(term string) ([]APISearch, error) { if err != nil { return nil, err } - - var outs []APISearch - for _, repo := range results.Results { - var out APISearch - out.Description = repo["description"] - out.Name = repo["name"] - outs = append(outs, out) - } - return outs, nil + return results.Results, nil } func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils.StreamFormatter) (string, error) {