1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

'docker ps' prints shorter lines

This commit is contained in:
Solomon Hykes 2013-01-29 03:18:07 -08:00
parent 279917e353
commit bcfe2aa2a7
3 changed files with 16 additions and 4 deletions

View file

@ -327,10 +327,11 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string)
"ps", "[OPTIONS]", "List containers")
quiet := cmd.Bool("q", false, "Only display numeric IDs")
fl_all := cmd.Bool("a", false, "Show all containers. Only running containers are shown by default.")
fl_full := cmd.Bool("notrunc", false, "Don't truncate output")
if err := cmd.Parse(args); err != nil {
return nil
}
w := tabwriter.NewWriter(stdout, 20, 1, 3, ' ', 0)
w := tabwriter.NewWriter(stdout, 12, 1, 3, ' ', 0)
if (!*quiet) {
fmt.Fprintf(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\n")
}
@ -339,10 +340,14 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string)
continue
}
if !*quiet {
command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
if !*fl_full {
command = docker.Trunc(command, 20)
}
for idx, field := range[]string {
/* ID */ container.Id,
/* IMAGE */ container.GetUserData("image"),
/* COMMAND */ fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " ")),
/* COMMAND */ command,
/* CREATED */ future.HumanDuration(time.Now().Sub(container.Created)) + " ago",
/* STATUS */ container.State.String(),
} {

View file

@ -28,9 +28,9 @@ func newState() *State {
// String returns a human-readable description of the state
func (s *State) String() string {
if s.Running {
return fmt.Sprintf("Running for %s", future.HumanDuration(time.Now().Sub(s.StartedAt)))
return fmt.Sprintf("Up %s", future.HumanDuration(time.Now().Sub(s.StartedAt)))
}
return fmt.Sprintf("Exited with %d", s.ExitCode)
return fmt.Sprintf("Exit %d", s.ExitCode)
}
func (s *State) setRunning(pid int) {

View file

@ -8,6 +8,13 @@ import (
"sync"
)
func Trunc(s string, maxlen int) string {
if len(s) <= maxlen {
return s
}
return s[:maxlen]
}
// Tar generates a tar archive from a filesystem path, and returns it as a stream.
// Path must point to a directory.