github.com/cspotcode/docker-cli@v20.10.0-rc1.0.20201201121459-3faad7acc5b8+incompatible/cli/command/formatter/custom.go (about) 1 package formatter 2 3 import "strings" 4 5 // Common header constants 6 const ( 7 CreatedSinceHeader = "CREATED" 8 CreatedAtHeader = "CREATED AT" 9 SizeHeader = "SIZE" 10 LabelsHeader = "LABELS" 11 NameHeader = "NAME" 12 DescriptionHeader = "DESCRIPTION" 13 DriverHeader = "DRIVER" 14 ScopeHeader = "SCOPE" 15 StateHeader = "STATE" 16 StatusHeader = "STATUS" 17 PortsHeader = "PORTS" 18 ImageHeader = "IMAGE" 19 ContainerIDHeader = "CONTAINER ID" 20 ) 21 22 // SubContext defines what Context implementation should provide 23 type SubContext interface { 24 FullHeader() interface{} 25 } 26 27 // SubHeaderContext is a map destined to formatter header (table format) 28 type SubHeaderContext map[string]string 29 30 // Label returns the header label for the specified string 31 func (c SubHeaderContext) Label(name string) string { 32 n := strings.Split(name, ".") 33 r := strings.NewReplacer("-", " ", "_", " ") 34 h := r.Replace(n[len(n)-1]) 35 36 return h 37 } 38 39 // HeaderContext provides the subContext interface for managing headers 40 type HeaderContext struct { 41 Header interface{} 42 } 43 44 // FullHeader returns the header as an interface 45 func (c *HeaderContext) FullHeader() interface{} { 46 return c.Header 47 } 48 49 func stripNamePrefix(ss []string) []string { 50 sss := make([]string, len(ss)) 51 for i, s := range ss { 52 sss[i] = s[1:] 53 } 54 55 return sss 56 }