mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
add ps -s
This commit is contained in:
parent
8a131dffb6
commit
bd04d7d475
3 changed files with 26 additions and 8 deletions
6
api.go
6
api.go
|
@ -248,6 +248,10 @@ func getContainersJSON(srv *Server, version float64, w http.ResponseWriter, r *h
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
size, err := getBoolParam(r.Form.Get("size"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
since := r.Form.Get("since")
|
||||
before := r.Form.Get("before")
|
||||
n, err := strconv.Atoi(r.Form.Get("limit"))
|
||||
|
@ -255,7 +259,7 @@ func getContainersJSON(srv *Server, version float64, w http.ResponseWriter, r *h
|
|||
n = -1
|
||||
}
|
||||
|
||||
outs := srv.Containers(all, n, since, before)
|
||||
outs := srv.Containers(all, size, n, since, before)
|
||||
b, err := json.Marshal(outs)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
21
commands.go
21
commands.go
|
@ -867,6 +867,7 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
|||
func (cli *DockerCli) CmdPs(args ...string) error {
|
||||
cmd := Subcmd("ps", "[OPTIONS]", "List containers")
|
||||
quiet := cmd.Bool("q", false, "Only display numeric IDs")
|
||||
size := cmd.Bool("s", false, "Display sizes")
|
||||
all := cmd.Bool("a", false, "Show all containers. Only running containers are shown by default.")
|
||||
noTrunc := cmd.Bool("notrunc", false, "Don't truncate output")
|
||||
nLatest := cmd.Bool("l", false, "Show only the latest created container, include non-running ones.")
|
||||
|
@ -893,6 +894,9 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
|||
if *before != "" {
|
||||
v.Set("before", *before)
|
||||
}
|
||||
if *size {
|
||||
v.Set("size", "1")
|
||||
}
|
||||
|
||||
body, _, err := cli.call("GET", "/containers/json?"+v.Encode(), nil)
|
||||
if err != nil {
|
||||
|
@ -906,7 +910,12 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
|||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
|
||||
if !*quiet {
|
||||
fmt.Fprintln(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tPORTS\tSIZE")
|
||||
fmt.Fprint(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tPORTS")
|
||||
if *size {
|
||||
fmt.Fprintln(w, "\tSIZE")
|
||||
} else {
|
||||
fmt.Fprint(w, "\n")
|
||||
}
|
||||
}
|
||||
|
||||
for _, out := range outs {
|
||||
|
@ -916,10 +925,14 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
|||
} else {
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\t", utils.TruncateID(out.ID), out.Image, utils.Trunc(out.Command, 20), utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports)
|
||||
}
|
||||
if out.SizeRootFs > 0 {
|
||||
fmt.Fprintf(w, "%s (virtual %s)\n", utils.HumanSize(out.SizeRw), utils.HumanSize(out.SizeRootFs))
|
||||
if *size {
|
||||
if out.SizeRootFs > 0 {
|
||||
fmt.Fprintf(w, "%s (virtual %s)\n", utils.HumanSize(out.SizeRw), utils.HumanSize(out.SizeRootFs))
|
||||
} else {
|
||||
fmt.Fprintf(w, "%s\n", utils.HumanSize(out.SizeRw))
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(w, "%s\n", utils.HumanSize(out.SizeRw))
|
||||
fmt.Fprint(w, "\n")
|
||||
}
|
||||
} else {
|
||||
if *noTrunc {
|
||||
|
|
|
@ -251,7 +251,7 @@ func (srv *Server) ContainerChanges(name string) ([]Change, error) {
|
|||
return nil, fmt.Errorf("No such container: %s", name)
|
||||
}
|
||||
|
||||
func (srv *Server) Containers(all bool, n int, since, before string) []APIContainers {
|
||||
func (srv *Server) Containers(all, size bool, n int, since, before string) []APIContainers {
|
||||
var foundBefore bool
|
||||
var displayed int
|
||||
retContainers := []APIContainers{}
|
||||
|
@ -285,8 +285,9 @@ func (srv *Server) Containers(all bool, n int, since, before string) []APIContai
|
|||
c.Created = container.Created.Unix()
|
||||
c.Status = container.State.String()
|
||||
c.Ports = container.NetworkSettings.PortMappingHuman()
|
||||
c.SizeRw, c.SizeRootFs = container.GetSize()
|
||||
|
||||
if size {
|
||||
c.SizeRw, c.SizeRootFs = container.GetSize()
|
||||
}
|
||||
retContainers = append(retContainers, c)
|
||||
}
|
||||
return retContainers
|
||||
|
|
Loading…
Reference in a new issue