Pārlūkot izejas kodu

'docker ps' prints shorter lines

Solomon Hykes 12 gadi atpakaļ
vecāks
revīzija
bcfe2aa2a7
3 mainītis faili ar 16 papildinājumiem un 4 dzēšanām
  1. 7 2
      dockerd/dockerd.go
  2. 2 2
      state.go
  3. 7 0
      utils.go

+ 7 - 2
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(),
 			} {

+ 2 - 2
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) {

+ 7 - 0
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.