mirror of https://github.com/docker/docs.git
Remove engine.Table from docker search and fix missing field
registry/SearchResults was missing the "is_automated" field. I added it back in. Pull this 'table' removal one from the others because it fixed a bug too Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
parent
12e7787540
commit
67b4cce0f6
|
@ -1,18 +1,25 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"github.com/docker/docker/engine"
|
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
"github.com/docker/docker/pkg/parsers"
|
"github.com/docker/docker/pkg/parsers"
|
||||||
"github.com/docker/docker/registry"
|
"github.com/docker/docker/registry"
|
||||||
"github.com/docker/docker/utils"
|
"github.com/docker/docker/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ByStars []registry.SearchResult
|
||||||
|
|
||||||
|
func (r ByStars) Len() int { return len(r) }
|
||||||
|
func (r ByStars) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
|
||||||
|
func (r ByStars) Less(i, j int) bool { return r[i].StarCount < r[j].StarCount }
|
||||||
|
|
||||||
// CmdSearch searches the Docker Hub for images.
|
// CmdSearch searches the Docker Hub for images.
|
||||||
//
|
//
|
||||||
// Usage: docker search [OPTIONS] TERM
|
// Usage: docker search [OPTIONS] TERM
|
||||||
|
@ -39,35 +46,37 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
|
||||||
|
|
||||||
cli.LoadConfigFile()
|
cli.LoadConfigFile()
|
||||||
|
|
||||||
body, statusCode, errReq := cli.clientRequestAttemptLogin("GET", "/images/search?"+v.Encode(), nil, nil, repoInfo.Index, "search")
|
rdr, _, err := cli.clientRequestAttemptLogin("GET", "/images/search?"+v.Encode(), nil, nil, repoInfo.Index, "search")
|
||||||
rawBody, _, err := readBody(body, statusCode, errReq)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
outs := engine.NewTable("star_count", 0)
|
results := ByStars{}
|
||||||
if _, err := outs.ReadListFrom(rawBody); err != nil {
|
err = json.NewDecoder(rdr).Decode(&results)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
outs.ReverseSort()
|
|
||||||
|
sort.Sort(sort.Reverse(results))
|
||||||
|
|
||||||
w := tabwriter.NewWriter(cli.out, 10, 1, 3, ' ', 0)
|
w := tabwriter.NewWriter(cli.out, 10, 1, 3, ' ', 0)
|
||||||
fmt.Fprintf(w, "NAME\tDESCRIPTION\tSTARS\tOFFICIAL\tAUTOMATED\n")
|
fmt.Fprintf(w, "NAME\tDESCRIPTION\tSTARS\tOFFICIAL\tAUTOMATED\n")
|
||||||
for _, out := range outs.Data {
|
for _, res := range results {
|
||||||
if ((*automated || *trusted) && (!out.GetBool("is_trusted") && !out.GetBool("is_automated"))) || (*stars > uint(out.GetInt("star_count"))) {
|
if ((*automated || *trusted) && (!res.IsTrusted && !res.IsAutomated)) || (int(*stars) > res.StarCount) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
desc := strings.Replace(out.Get("description"), "\n", " ", -1)
|
desc := strings.Replace(res.Description, "\n", " ", -1)
|
||||||
desc = strings.Replace(desc, "\r", " ", -1)
|
desc = strings.Replace(desc, "\r", " ", -1)
|
||||||
if !*noTrunc && len(desc) > 45 {
|
if !*noTrunc && len(desc) > 45 {
|
||||||
desc = utils.Trunc(desc, 42) + "..."
|
desc = utils.Trunc(desc, 42) + "..."
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, "%s\t%s\t%d\t", out.Get("name"), desc, uint(out.GetInt("star_count")))
|
fmt.Fprintf(w, "%s\t%s\t%d\t", res.Name, desc, res.StarCount)
|
||||||
if out.GetBool("is_official") {
|
if res.IsOfficial {
|
||||||
fmt.Fprint(w, "[OK]")
|
fmt.Fprint(w, "[OK]")
|
||||||
|
|
||||||
}
|
}
|
||||||
fmt.Fprint(w, "\t")
|
fmt.Fprint(w, "\t")
|
||||||
if out.GetBool("is_automated") || out.GetBool("is_trusted") {
|
if res.IsAutomated || res.IsTrusted {
|
||||||
fmt.Fprint(w, "[OK]")
|
fmt.Fprint(w, "[OK]")
|
||||||
}
|
}
|
||||||
fmt.Fprint(w, "\n")
|
fmt.Fprint(w, "\n")
|
||||||
|
|
|
@ -5,6 +5,7 @@ type SearchResult struct {
|
||||||
IsOfficial bool `json:"is_official"`
|
IsOfficial bool `json:"is_official"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
IsTrusted bool `json:"is_trusted"`
|
IsTrusted bool `json:"is_trusted"`
|
||||||
|
IsAutomated bool `json:"is_automated"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue