Skip to content

Commit

Permalink
Merge pull request moby#30776 from WeiZhang555/stats-all-format-name-…
Browse files Browse the repository at this point in the history
…panic-cli

Fix panic of "docker stats --format {{.Name}} --all"
  • Loading branch information
LK4D4 authored Feb 8, 2017
2 parents 846b787 + 5a7b3c7 commit f5116c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cli/command/formatter/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ func (c *containerStatsContext) Container() string {

func (c *containerStatsContext) Name() string {
c.AddHeader(nameHeader)
name := c.s.Name[1:]
return name
if len(c.s.Name) > 1 {
return c.s.Name[1:]
}
return "--"
}

func (c *containerStatsContext) ID() string {
Expand Down
8 changes: 8 additions & 0 deletions cli/command/formatter/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ func TestContainerStatsContextWrite(t *testing.T) {
`MEM USAGE / LIMIT
20B / 20B
-- / --
`,
},
{
Context{Format: "{{.Container}} {{.ID}} {{.Name}}"},
`container1 abcdef foo
container2 --
`,
},
{
Expand All @@ -84,6 +90,8 @@ container2 --
stats := []StatsEntry{
{
Container: "container1",
ID: "abcdef",
Name: "/foo",
CPUPercentage: 20,
Memory: 20,
MemoryLimit: 20,
Expand Down

0 comments on commit f5116c6

Please sign in to comment.