mirror of https://github.com/docker/docs.git
'docker ps' prints shorter lines
This commit is contained in:
parent
279917e353
commit
bcfe2aa2a7
|
@ -327,10 +327,11 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string)
|
||||||
"ps", "[OPTIONS]", "List containers")
|
"ps", "[OPTIONS]", "List containers")
|
||||||
quiet := cmd.Bool("q", false, "Only display numeric IDs")
|
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_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 {
|
if err := cmd.Parse(args); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(stdout, 20, 1, 3, ' ', 0)
|
w := tabwriter.NewWriter(stdout, 12, 1, 3, ' ', 0)
|
||||||
if (!*quiet) {
|
if (!*quiet) {
|
||||||
fmt.Fprintf(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\n")
|
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
|
continue
|
||||||
}
|
}
|
||||||
if !*quiet {
|
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 {
|
for idx, field := range[]string {
|
||||||
/* ID */ container.Id,
|
/* ID */ container.Id,
|
||||||
/* IMAGE */ container.GetUserData("image"),
|
/* 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",
|
/* CREATED */ future.HumanDuration(time.Now().Sub(container.Created)) + " ago",
|
||||||
/* STATUS */ container.State.String(),
|
/* STATUS */ container.State.String(),
|
||||||
} {
|
} {
|
||||||
|
|
4
state.go
4
state.go
|
@ -28,9 +28,9 @@ func newState() *State {
|
||||||
// String returns a human-readable description of the state
|
// String returns a human-readable description of the state
|
||||||
func (s *State) String() string {
|
func (s *State) String() string {
|
||||||
if s.Running {
|
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) {
|
func (s *State) setRunning(pid int) {
|
||||||
|
|
7
utils.go
7
utils.go
|
@ -8,6 +8,13 @@ import (
|
||||||
"sync"
|
"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.
|
// Tar generates a tar archive from a filesystem path, and returns it as a stream.
|
||||||
// Path must point to a directory.
|
// Path must point to a directory.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue