2016-09-08 13:11:39 -04:00
|
|
|
package formatter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
imageHeader = "IMAGE"
|
|
|
|
createdSinceHeader = "CREATED"
|
|
|
|
createdAtHeader = "CREATED AT"
|
|
|
|
sizeHeader = "SIZE"
|
|
|
|
labelsHeader = "LABELS"
|
|
|
|
nameHeader = "NAME"
|
|
|
|
driverHeader = "DRIVER"
|
|
|
|
scopeHeader = "SCOPE"
|
|
|
|
)
|
|
|
|
|
|
|
|
type subContext interface {
|
2016-09-12 16:59:18 -04:00
|
|
|
FullHeader() string
|
|
|
|
AddHeader(header string)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
2016-09-12 16:59:18 -04:00
|
|
|
// HeaderContext provides the subContext interface for managing headers
|
|
|
|
type HeaderContext struct {
|
2016-09-08 13:11:39 -04:00
|
|
|
header []string
|
|
|
|
}
|
|
|
|
|
2016-09-12 16:59:18 -04:00
|
|
|
// FullHeader returns the header as a string
|
|
|
|
func (c *HeaderContext) FullHeader() string {
|
2016-09-08 13:11:39 -04:00
|
|
|
if c.header == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return strings.Join(c.header, "\t")
|
|
|
|
}
|
|
|
|
|
2016-09-12 16:59:18 -04:00
|
|
|
// AddHeader adds another column to the header
|
|
|
|
func (c *HeaderContext) AddHeader(header string) {
|
2016-09-08 13:11:39 -04:00
|
|
|
if c.header == nil {
|
|
|
|
c.header = []string{}
|
|
|
|
}
|
|
|
|
c.header = append(c.header, strings.ToUpper(header))
|
|
|
|
}
|
|
|
|
|
|
|
|
func stripNamePrefix(ss []string) []string {
|
|
|
|
sss := make([]string, len(ss))
|
|
|
|
for i, s := range ss {
|
|
|
|
sss[i] = s[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
return sss
|
|
|
|
}
|