custom.go 836 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package formatter
  2. import (
  3. "strings"
  4. )
  5. const (
  6. tableKey = "table"
  7. imageHeader = "IMAGE"
  8. createdSinceHeader = "CREATED"
  9. createdAtHeader = "CREATED AT"
  10. sizeHeader = "SIZE"
  11. labelsHeader = "LABELS"
  12. nameHeader = "NAME"
  13. driverHeader = "DRIVER"
  14. )
  15. type subContext interface {
  16. fullHeader() string
  17. addHeader(header string)
  18. }
  19. type baseSubContext struct {
  20. header []string
  21. }
  22. func (c *baseSubContext) fullHeader() string {
  23. if c.header == nil {
  24. return ""
  25. }
  26. return strings.Join(c.header, "\t")
  27. }
  28. func (c *baseSubContext) addHeader(header string) {
  29. if c.header == nil {
  30. c.header = []string{}
  31. }
  32. c.header = append(c.header, strings.ToUpper(header))
  33. }
  34. func stripNamePrefix(ss []string) []string {
  35. sss := make([]string, len(ss))
  36. for i, s := range ss {
  37. sss[i] = s[1:]
  38. }
  39. return sss
  40. }