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"
|
2022-11-28 10:27:45 -05:00
|
|
|
ErrorHeader = "ERROR"
|
2018-10-23 11:05:44 -04:00
|
|
|
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 {
|
2023-11-20 12:04:36 -05:00
|
|
|
FullHeader() any
|
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 {
|
2023-11-20 12:04:36 -05:00
|
|
|
Header any
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
2017-02-03 19:48:46 -05:00
|
|
|
// FullHeader returns the header as an interface
|
2023-11-20 12:04:36 -05:00
|
|
|
func (c *HeaderContext) FullHeader() any {
|
2018-10-23 11:05:44 -04:00
|
|
|
return c.Header
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|