diff --git a/dockerd/dockerd.go b/dockerd/dockerd.go index d99ffc7022..9fb7e27482 100644 --- a/dockerd/dockerd.go +++ b/dockerd/dockerd.go @@ -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(), } { diff --git a/state.go b/state.go index dfcf6c25a6..e864f304f9 100644 --- a/state.go +++ b/state.go @@ -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) { diff --git a/utils.go b/utils.go index 034b561013..b021ef8c03 100644 --- a/utils.go +++ b/utils.go @@ -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.