mirror of
https://github.com/docker/cli.git
synced 2026-11-01 23:35:23 +03:00
Merge pull request #6874 from thaJeztah/future_proof_prefix
formatting: only strip "/" prefixes
This commit is contained in:
@@ -2,6 +2,7 @@ package container
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/docker/cli/cli/command/formatter"
|
||||
@@ -167,9 +168,9 @@ func (c *statsContext) Container() string {
|
||||
}
|
||||
|
||||
func (c *statsContext) Name() string {
|
||||
// TODO(thaJeztah): make this explicitly trim the "/" prefix, not just any char.
|
||||
if len(c.s.Name) > 1 {
|
||||
return c.s.Name[1:]
|
||||
// Trim the "/" prefix (if present).
|
||||
if name := strings.TrimPrefix(c.s.Name, "/"); name != "" {
|
||||
return name
|
||||
}
|
||||
return noValue
|
||||
}
|
||||
|
||||
@@ -155,11 +155,12 @@ func (c *ContainerContext) Names() string {
|
||||
return strings.Join(names, ",")
|
||||
}
|
||||
|
||||
// StripNamePrefix removes prefix from string, typically container names as returned by `ContainersList` API
|
||||
// StripNamePrefix removes any "/" prefix from container names returned
|
||||
// by the "ContainersList" API.
|
||||
func StripNamePrefix(ss []string) []string {
|
||||
sss := make([]string, len(ss))
|
||||
for i, s := range ss {
|
||||
sss[i] = s[1:]
|
||||
sss[i] = strings.TrimPrefix(s, "/")
|
||||
}
|
||||
return sss
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user