diff --git a/api.go b/api.go index 84b5a6dfb2..8df3291357 100644 --- a/api.go +++ b/api.go @@ -129,9 +129,8 @@ func getImagesJson(srv *Server, w http.ResponseWriter, r *http.Request, vars map all := r.Form.Get("all") == "1" filter := r.Form.Get("filter") - only_ids := r.Form.Get("only_ids") == "1" - outs, err := srv.Images(all, only_ids, filter) + outs, err := srv.Images(all, filter) if err != nil { return err } @@ -199,8 +198,6 @@ func getContainersPs(srv *Server, w http.ResponseWriter, r *http.Request, vars m return err } all := r.Form.Get("all") == "1" - trunc_cmd := r.Form.Get("trunc_cmd") != "0" - only_ids := r.Form.Get("only_ids") == "1" since := r.Form.Get("since") before := r.Form.Get("before") n, err := strconv.Atoi(r.Form.Get("limit")) @@ -208,7 +205,7 @@ func getContainersPs(srv *Server, w http.ResponseWriter, r *http.Request, vars m n = -1 } - outs := srv.Containers(all, trunc_cmd, only_ids, n, since, before) + outs := srv.Containers(all, n, since, before) b, err := json.Marshal(outs) if err != nil { return err diff --git a/api_params.go b/api_params.go index c7c15585f9..e6f1c1b0b4 100644 --- a/api_params.go +++ b/api_params.go @@ -10,7 +10,7 @@ type ApiImages struct { Repository string `json:",omitempty"` Tag string `json:",omitempty"` Id string - Created int64 `json:",omitempty"` + Created int64 } type ApiInfo struct { @@ -25,11 +25,11 @@ type ApiInfo struct { type ApiContainers struct { Id string - Image string `json:",omitempty"` - Command string `json:",omitempty"` - Created int64 `json:",omitempty"` - Status string `json:",omitempty"` - Ports string `json:",omitempty"` + Image string + Command string + Created int64 + Status string + Ports string } type ApiSearch struct { diff --git a/api_test.go b/api_test.go index 2128f3ef35..5096b05212 100644 --- a/api_test.go +++ b/api_test.go @@ -115,8 +115,8 @@ func TestGetImagesJson(t *testing.T) { srv := &Server{runtime: runtime} - // only_ids=0&all=0 - req, err := http.NewRequest("GET", "/images/json?only_ids=0&all=0", nil) + // all=0 + req, err := http.NewRequest("GET", "/images/json?all=0", nil) if err != nil { t.Fatal(err) } @@ -142,8 +142,8 @@ func TestGetImagesJson(t *testing.T) { r2 := httptest.NewRecorder() - // only_ids=1&all=1 - req2, err := http.NewRequest("GET", "/images/json?only_ids=1&all=1", nil) + // all=1 + req2, err := http.NewRequest("GET", "/images/json?all=1", nil) if err != nil { t.Fatal(err) } @@ -161,12 +161,8 @@ func TestGetImagesJson(t *testing.T) { t.Errorf("Excepted 1 image, %d found", len(images2)) } - if images2[0].Repository != "" { - t.Errorf("Excepted no image Repository, %s found", images2[0].Repository) - } - - if images2[0].Id != GetTestImage(runtime).ShortId() { - t.Errorf("Retrieved image Id differs, expected %s, received %s", GetTestImage(runtime).ShortId(), images2[0].Id) + if images2[0].Id != GetTestImage(runtime).Id { + t.Errorf("Retrieved image Id differs, expected %s, received %s", GetTestImage(runtime).Id, images2[0].Id) } r3 := httptest.NewRecorder() @@ -329,8 +325,8 @@ func TestGetContainersPs(t *testing.T) { if len(containers) != 1 { t.Fatalf("Excepted %d container, %d found", 1, len(containers)) } - if containers[0].Id != container.ShortId() { - t.Fatalf("Container ID mismatch. Expected: %s, received: %s\n", container.ShortId(), containers[0].Id) + if containers[0].Id != container.Id { + t.Fatalf("Container ID mismatch. Expected: %s, received: %s\n", container.Id, containers[0].Id) } } diff --git a/commands.go b/commands.go index a8363925b2..9e26790f5d 100644 --- a/commands.go +++ b/commands.go @@ -687,6 +687,7 @@ func CmdImages(args ...string) error { cmd := Subcmd("images", "[OPTIONS] [NAME]", "List images") quiet := cmd.Bool("q", false, "only show numeric IDs") all := cmd.Bool("a", false, "show all images") + noTrunc := cmd.Bool("notrunc", false, "Don't truncate output") flViz := cmd.Bool("viz", false, "output graph in graphviz format") if err := cmd.Parse(args); err != nil { @@ -708,9 +709,6 @@ func CmdImages(args ...string) error { if cmd.NArg() == 1 { v.Set("filter", cmd.Arg(0)) } - if *quiet { - v.Set("only_ids", "1") - } if *all { v.Set("all", "1") } @@ -732,10 +730,27 @@ func CmdImages(args ...string) error { } for _, out := range outs { + if out.Repository == "" { + out.Repository = "" + } + if out.Tag == "" { + out.Tag = "" + } + if !*quiet { - fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\n", out.Repository, out.Tag, out.Id, HumanDuration(time.Now().Sub(time.Unix(out.Created, 0)))) + fmt.Fprintf(w, "%s\t%s\t", out.Repository, out.Tag) + if *noTrunc { + fmt.Fprintf(w, "%s\t", out.Id) + } else { + fmt.Fprintf(w, "%s\t", TruncateId(out.Id)) + } + fmt.Fprintf(w, "%s ago\n", HumanDuration(time.Now().Sub(time.Unix(out.Created, 0)))) } else { - fmt.Fprintln(w, out.Id) + if *noTrunc { + fmt.Fprintln(w, out.Id) + } else { + fmt.Fprintln(w, TruncateId(out.Id)) + } } } @@ -763,15 +778,9 @@ func CmdPs(args ...string) error { if *last == -1 && *nLatest { *last = 1 } - if *quiet { - v.Set("only_ids", "1") - } if *all { v.Set("all", "1") } - if *noTrunc { - v.Set("trunc_cmd", "0") - } if *last != -1 { v.Set("limit", strconv.Itoa(*last)) } @@ -799,9 +808,17 @@ func CmdPs(args ...string) error { for _, out := range outs { if !*quiet { - fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", out.Id, out.Image, out.Command, out.Status, HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports) + if *noTrunc { + fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", out.Id, out.Image, out.Command, out.Status, HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports) + } else { + fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", TruncateId(out.Id), out.Image, Trunc(out.Command, 20), out.Status, HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports) + } } else { - fmt.Fprintln(w, out.Id) + if *noTrunc { + fmt.Fprintln(w, out.Id) + } else { + fmt.Fprintln(w, TruncateId(out.Id)) + } } } diff --git a/docs/sources/remote-api/api.rst b/docs/sources/remote-api/api.rst index a6f0662644..b29fd65d02 100644 --- a/docs/sources/remote-api/api.rst +++ b/docs/sources/remote-api/api.rst @@ -28,7 +28,7 @@ List containers .. sourcecode:: http - GET /containers/ps?trunc_cmd=0&all=1&only_ids=0&before=8dfafdbc3a40 HTTP/1.1 + GET /containers/ps?trunc_cmd=0&all=1&before=8dfafdbc3a40 HTTP/1.1 **Example response**: @@ -68,9 +68,7 @@ List containers } ] - :query only_ids: 1 or 0, Only display numeric IDs. Default 0 :query all: 1 or 0, Show all containers. Only running containers are shown by default - :query trunc_cmd: 1 or 0, Truncate output. Output is truncated by default :query limit: Show ``limit`` last created containers, include non-running ones. :query since: Show only containers created since Id, include non-running ones. :query before: Show only containers created before Id, include non-running ones. @@ -467,7 +465,7 @@ List Images .. sourcecode:: http - GET /images/json?all=0&only_ids=0 HTTP/1.1 + GET /images/json?all=0 HTTP/1.1 **Example response**: @@ -523,7 +521,6 @@ List Images base [style=invisible] } - :query only_ids: 1 or 0, Only display numeric IDs. Default 0 :query all: 1 or 0, Show all containers. Only running containers are shown by default :statuscode 200: no error :statuscode 500: server error diff --git a/server.go b/server.go index e96497bff3..453574946d 100644 --- a/server.go +++ b/server.go @@ -135,7 +135,7 @@ func (srv *Server) ImagesViz(out io.Writer) error { return nil } -func (srv *Server) Images(all, only_ids bool, filter string) ([]ApiImages, error) { +func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) { var allImages map[string]*Image var err error if all { @@ -159,29 +159,19 @@ func (srv *Server) Images(all, only_ids bool, filter string) ([]ApiImages, error continue } delete(allImages, id) - if !only_ids { - out.Repository = name - out.Tag = tag - out.Id = TruncateId(id) - out.Created = image.Created.Unix() - } else { - out.Id = image.ShortId() - } + out.Repository = name + out.Tag = tag + out.Id = image.Id + out.Created = image.Created.Unix() outs = append(outs, out) } } // Display images which aren't part of a if filter == "" { - for id, image := range allImages { + for _, image := range allImages { var out ApiImages - if !only_ids { - out.Repository = "" - out.Tag = "" - out.Id = TruncateId(id) - out.Created = image.Created.Unix() - } else { - out.Id = image.ShortId() - } + out.Id = image.Id + out.Created = image.Created.Unix() outs = append(outs, out) } } @@ -235,7 +225,7 @@ func (srv *Server) ContainerChanges(name string) ([]Change, error) { return nil, fmt.Errorf("No such container: %s", name) } -func (srv *Server) Containers(all, trunc_cmd, only_ids bool, n int, since, before string) []ApiContainers { +func (srv *Server) Containers(all bool, n int, since, before string) []ApiContainers { var foundBefore bool var displayed int retContainers := []ApiContainers{} @@ -264,23 +254,11 @@ func (srv *Server) Containers(all, trunc_cmd, only_ids bool, n int, since, befor c := ApiContainers{ Id: container.Id, } - if trunc_cmd { - c = ApiContainers{ - Id: container.ShortId(), - } - } - - if !only_ids { - command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " ")) - if trunc_cmd { - command = Trunc(command, 20) - } - c.Image = srv.runtime.repositories.ImageName(container.Image) - c.Command = command - c.Created = container.Created.Unix() - c.Status = container.State.String() - c.Ports = container.NetworkSettings.PortMappingHuman() - } + c.Image = srv.runtime.repositories.ImageName(container.Image) + c.Command = fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " ")) + c.Created = container.Created.Unix() + c.Status = container.State.String() + c.Ports = container.NetworkSettings.PortMappingHuman() retContainers = append(retContainers, c) } return retContainers