File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed
Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package container
22
33import (
44 "strconv"
5+ "strings"
56 "sync"
67
78 "github.com/docker/cli/cli/command/formatter"
@@ -167,9 +168,9 @@ func (c *statsContext) Container() string {
167168}
168169
169170func (c * statsContext ) Name () string {
170- // TODO(thaJeztah): make this explicitly trim the "/" prefix, not just any char .
171- if len (c .s .Name ) > 1 {
172- return c . s . Name [ 1 :]
171+ // Trim the "/" prefix (if present) .
172+ if name := strings . TrimPrefix (c .s .Name , "/" ); name != "" {
173+ return name
173174 }
174175 return noValue
175176}
Original file line number Diff line number Diff line change @@ -155,11 +155,12 @@ func (c *ContainerContext) Names() string {
155155 return strings .Join (names , "," )
156156}
157157
158- // StripNamePrefix removes prefix from string, typically container names as returned by `ContainersList` API
158+ // StripNamePrefix removes any "/" prefix from container names returned
159+ // by the "ContainersList" API.
159160func StripNamePrefix (ss []string ) []string {
160161 sss := make ([]string , len (ss ))
161162 for i , s := range ss {
162- sss [i ] = s [ 1 :]
163+ sss [i ] = strings . TrimPrefix ( s , "/" )
163164 }
164165 return sss
165166}
You can’t perform that action at this time.
0 commit comments