Browse code

'docker ps' prints shorter lines

Solomon Hykes authored on 2013/01/29 20:18:07
Showing 3 changed files
... ...
@@ -327,10 +327,11 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string)
327 327
 		"ps", "[OPTIONS]", "List containers")
328 328
 	quiet := cmd.Bool("q", false, "Only display numeric IDs")
329 329
 	fl_all := cmd.Bool("a", false, "Show all containers. Only running containers are shown by default.")
330
+	fl_full := cmd.Bool("notrunc", false, "Don't truncate output")
330 331
 	if err := cmd.Parse(args); err != nil {
331 332
 		return nil
332 333
 	}
333
-	w := tabwriter.NewWriter(stdout, 20, 1, 3, ' ', 0)
334
+	w := tabwriter.NewWriter(stdout, 12, 1, 3, ' ', 0)
334 335
 	if (!*quiet) {
335 336
 		fmt.Fprintf(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\n")
336 337
 	}
... ...
@@ -339,10 +340,14 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string)
339 339
 			continue
340 340
 		}
341 341
 		if !*quiet {
342
+			command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
343
+			if !*fl_full {
344
+				command = docker.Trunc(command, 20)
345
+			}
342 346
 			for idx, field := range[]string {
343 347
 				/* ID */	container.Id,
344 348
 				/* IMAGE */	container.GetUserData("image"),
345
-				/* COMMAND */	fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " ")),
349
+				/* COMMAND */	command,
346 350
 				/* CREATED */	future.HumanDuration(time.Now().Sub(container.Created)) + " ago",
347 351
 				/* STATUS */	container.State.String(),
348 352
 			} {
... ...
@@ -28,9 +28,9 @@ func newState() *State {
28 28
 // String returns a human-readable description of the state
29 29
 func (s *State) String() string {
30 30
 	if s.Running {
31
-		return fmt.Sprintf("Running for %s", future.HumanDuration(time.Now().Sub(s.StartedAt)))
31
+		return fmt.Sprintf("Up %s", future.HumanDuration(time.Now().Sub(s.StartedAt)))
32 32
 	}
33
-	return fmt.Sprintf("Exited with %d", s.ExitCode)
33
+	return fmt.Sprintf("Exit %d", s.ExitCode)
34 34
 }
35 35
 
36 36
 func (s *State) setRunning(pid int) {
... ...
@@ -8,6 +8,13 @@ import (
8 8
 	"sync"
9 9
 )
10 10
 
11
+func Trunc(s string, maxlen int) string {
12
+	if len(s) <= maxlen {
13
+		return s
14
+	}
15
+	return s[:maxlen]
16
+}
17
+
11 18
 // Tar generates a tar archive from a filesystem path, and returns it as a stream.
12 19
 // Path must point to a directory.
13 20