Pārlūkot izejas kodu

update docker search to reflect future changes of the api

Victor Vieux 11 gadi atpakaļ
vecāks
revīzija
02b5202432
4 mainītis faili ar 27 papildinājumiem un 23 dzēšanām
  1. 0 5
      api_params.go
  2. 14 5
      commands.go
  3. 11 3
      registry/registry.go
  4. 2 10
      server.go

+ 0 - 5
api_params.go

@@ -78,11 +78,6 @@ type APIContainersOld struct {
 	SizeRootFs int64
 	SizeRootFs int64
 }
 }
 
 
-type APISearch struct {
-	Name        string
-	Description string
-}
-
 type APIID struct {
 type APIID struct {
 	ID string `json:"Id"`
 	ID string `json:"Id"`
 }
 }

+ 14 - 5
commands.go

@@ -1420,19 +1420,19 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
 		return err
 		return err
 	}
 	}
 
 
-	outs := []APISearch{}
+	outs := []registry.SearchResult{}
 	err = json.Unmarshal(body, &outs)
 	err = json.Unmarshal(body, &outs)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
 	fmt.Fprintf(cli.out, "Found %d results matching your query (\"%s\")\n", len(outs), cmd.Arg(0))
 	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")
+	w := tabwriter.NewWriter(cli.out, 10, 1, 3, ' ', 0)
+	fmt.Fprintf(w, "NAME\tDESCRIPTION\tSTARS\tOFFICIAL\tTRUSTED\n")
 	_, width := cli.getTtySize()
 	_, width := cli.getTtySize()
 	if width == 0 {
 	if width == 0 {
 		width = 45
 		width = 45
 	} else {
 	} else {
-		width = width - 33 //remote the first column
+		width = width - 10 - 54 //remote the first column
 	}
 	}
 	for _, out := range outs {
 	for _, out := range outs {
 		desc := strings.Replace(out.Description, "\n", " ", -1)
 		desc := strings.Replace(out.Description, "\n", " ", -1)
@@ -1440,7 +1440,16 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
 		if !*noTrunc && len(desc) > width {
 		if !*noTrunc && len(desc) > width {
 			desc = utils.Trunc(desc, width-3) + "..."
 			desc = utils.Trunc(desc, width-3) + "..."
 		}
 		}
-		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()
 	w.Flush()
 	return nil
 	return nil

+ 11 - 3
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 {
 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 {
 type RepositoryData struct {

+ 2 - 10
server.go

@@ -183,7 +183,7 @@ func (srv *Server) ContainerExport(name string, out io.Writer) error {
 	return fmt.Errorf("No such container: %s", name)
 	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))
 	r, err := registry.NewRegistry(srv.runtime.config.Root, nil, srv.HTTPRequestFactory(nil))
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
@@ -192,15 +192,7 @@ func (srv *Server) ImagesSearch(term string) ([]APISearch, error) {
 	if err != nil {
 	if err != nil {
 		return nil, err
 		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) {
 func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils.StreamFormatter) (string, error) {