2016-09-08 13:11:39 -04:00
|
|
|
package formatter
|
|
|
|
|
2018-10-23 11:05:44 -04:00
|
|
|
import "strings"
|
|
|
|
|
|
|
|
// Common header constants
|
2016-09-08 13:11:39 -04:00
|
|
|
const (
|
2018-10-23 11:05:44 -04:00
|
|
|
CreatedSinceHeader = "CREATED"
|
|
|
|
CreatedAtHeader = "CREATED AT"
|
|
|
|
SizeHeader = "SIZE"
|
|
|
|
LabelsHeader = "LABELS"
|
|
|
|
NameHeader = "NAME"
|
|
|
|
DescriptionHeader = "DESCRIPTION"
|
|
|
|
DriverHeader = "DRIVER"
|
|
|
|
ScopeHeader = "SCOPE"
|
2019-07-12 07:10:08 -04:00
|
|
|
StateHeader = "STATE"
|
2018-10-23 11:05:44 -04:00
|
|
|
StatusHeader = "STATUS"
|
|
|
|
PortsHeader = "PORTS"
|
|
|
|
ImageHeader = "IMAGE"
|
|
|
|
ContainerIDHeader = "CONTAINER ID"
|
2016-09-08 13:11:39 -04:00
|
|
|
)
|
|
|
|
|
2018-10-23 11:05:44 -04:00
|
|
|
// SubContext defines what Context implementation should provide
|
|
|
|
type SubContext interface {
|
2017-02-03 19:48:46 -05:00
|
|
|
FullHeader() interface{}
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
2018-10-23 11:05:44 -04:00
|
|
|
// SubHeaderContext is a map destined to formatter header (table format)
|
|
|
|
type SubHeaderContext map[string]string
|
|
|
|
|
|
|
|
// Label returns the header label for the specified string
|
|
|
|
func (c SubHeaderContext) Label(name string) string {
|
|
|
|
n := strings.Split(name, ".")
|
|
|
|
r := strings.NewReplacer("-", " ", "_", " ")
|
|
|
|
h := r.Replace(n[len(n)-1])
|
|
|
|
|
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
2016-09-12 16:59:18 -04:00
|
|
|
// HeaderContext provides the subContext interface for managing headers
|
|
|
|
type HeaderContext struct {
|
2018-10-23 11:05:44 -04:00
|
|
|
Header interface{}
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
2017-02-03 19:48:46 -05:00
|
|
|
// FullHeader returns the header as an interface
|
|
|
|
func (c *HeaderContext) FullHeader() interface{} {
|
2018-10-23 11:05:44 -04:00
|
|
|
return c.Header
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func stripNamePrefix(ss []string) []string {
|
|
|
|
sss := make([]string, len(ss))
|
|
|
|
for i, s := range ss {
|
|
|
|
sss[i] = s[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
return sss
|
|
|
|
}
|