Documentation ¶
Index ¶
- Constants
- func BuildCacheWrite(ctx Context, buildCaches []*types.BuildCache) error
- func ClientContextWrite(ctx Context, contexts []*ClientContext) error
- func ContainerWrite(ctx Context, containers []types.Container) error
- func DisplayablePorts(ports []types.Port) string
- func Ellipsis(s string, maxDisplayWidth int) string
- func ImageWrite(ctx ImageContext, images []types.ImageSummary) error
- func MarshalJSON(x interface{}) ([]byte, error)
- func StripNamePrefix(ss []string) []string
- func VolumeWrite(ctx Context, volumes []*volume.Volume) error
- type ClientContext
- type ContainerContext
- func (c *ContainerContext) Command() string
- func (c *ContainerContext) CreatedAt() string
- func (c *ContainerContext) ID() string
- func (c *ContainerContext) Image() string
- func (c *ContainerContext) Label(name string) string
- func (c *ContainerContext) Labels() string
- func (c *ContainerContext) LocalVolumes() string
- func (c *ContainerContext) MarshalJSON() ([]byte, error)
- func (c *ContainerContext) Mounts() string
- func (c *ContainerContext) Names() string
- func (c *ContainerContext) Networks() string
- func (c *ContainerContext) Ports() string
- func (c *ContainerContext) RunningFor() string
- func (c *ContainerContext) Size() string
- func (c *ContainerContext) State() string
- func (c *ContainerContext) Status() string
- type Context
- type DiskUsageContext
- type Format
- func NewBuildCacheFormat(source string, quiet bool) Format
- func NewClientContextFormat(source string, quiet bool) Format
- func NewContainerFormat(source string, quiet bool, size bool) Format
- func NewDiskUsageFormat(source string, verbose bool) Format
- func NewImageFormat(source string, quiet bool, digest bool) Format
- func NewVolumeFormat(source string, quiet bool) Format
- type HeaderContext
- type ImageContext
- type SubContext
- type SubFormat
- type SubHeaderContext
Constants ¶
const ( CreatedSinceHeader = "CREATED" CreatedAtHeader = "CREATED AT" SizeHeader = "SIZE" LabelsHeader = "LABELS" NameHeader = "NAME" DescriptionHeader = "DESCRIPTION" DriverHeader = "DRIVER" ScopeHeader = "SCOPE" StateHeader = "STATE" StatusHeader = "STATUS" PortsHeader = "PORTS" ImageHeader = "IMAGE" ErrorHeader = "ERROR" ContainerIDHeader = "CONTAINER ID" )
Common header constants
const ( TableFormatKey = "table" RawFormatKey = "raw" PrettyFormatKey = "pretty" JSONFormatKey = "json" DefaultQuietFormat = "{{.ID}}" JSONFormat = "{{json .}}" )
Format keys used to specify certain kinds of output formats
const (
// ClientContextTableFormat is the default client context format.
ClientContextTableFormat = "table {{.Name}}{{if .Current}} *{{end}}\t{{.Description}}\t{{.DockerEndpoint}}\t{{.Error}}"
)
Variables ¶
This section is empty.
Functions ¶
func BuildCacheWrite ¶
func BuildCacheWrite(ctx Context, buildCaches []*types.BuildCache) error
BuildCacheWrite renders the context for a list of containers
func ClientContextWrite ¶
func ClientContextWrite(ctx Context, contexts []*ClientContext) error
ClientContextWrite writes formatted contexts using the Context
func ContainerWrite ¶
ContainerWrite renders the context for a list of containers
func DisplayablePorts ¶
DisplayablePorts returns formatted string representing open ports of container e.g. "0.0.0.0:80->9090/tcp, 9988/tcp" it's used by command 'docker ps'
func Ellipsis ¶
Ellipsis truncates a string to fit within maxDisplayWidth, and appends ellipsis (…). For maxDisplayWidth of 1 and lower, no ellipsis is appended. For maxDisplayWidth of 1, first char of string will return even if its width > 1.
func ImageWrite ¶
func ImageWrite(ctx ImageContext, images []types.ImageSummary) error
ImageWrite writes the formatter images using the ImageContext
func MarshalJSON ¶
MarshalJSON marshals x into json It differs a bit from encoding/json MarshalJSON function for formatter
func StripNamePrefix ¶
StripNamePrefix removes prefix from string, typically container names as returned by `ContainersList` API
Types ¶
type ClientContext ¶
type ClientContext struct { Name string Description string DockerEndpoint string Current bool Error string }
ClientContext is a context for display
type ContainerContext ¶
type ContainerContext struct { HeaderContext // FieldsUsed is used in the pre-processing step to detect which fields are // used in the template. It's currently only used to detect use of the .Size // field which (if used) automatically sets the '--size' option when making // the API call. FieldsUsed map[string]interface{} // contains filtered or unexported fields }
ContainerContext is a struct used for rendering a list of containers in a Go template.
func NewContainerContext ¶
func NewContainerContext() *ContainerContext
NewContainerContext creates a new context for rendering containers
func (*ContainerContext) Command ¶
func (c *ContainerContext) Command() string
Command returns's the container's command. If the trunc option is set, the returned command is truncated (ellipsized).
func (*ContainerContext) CreatedAt ¶
func (c *ContainerContext) CreatedAt() string
CreatedAt returns the "Created" date/time of the container as a unix timestamp.
func (*ContainerContext) ID ¶
func (c *ContainerContext) ID() string
ID returns the container's ID as a string. Depending on the `--no-trunc` option being set, the full or truncated ID is returned.
func (*ContainerContext) Image ¶
func (c *ContainerContext) Image() string
Image returns the container's image reference. If the trunc option is set, the image's registry digest can be included.
func (*ContainerContext) Label ¶
func (c *ContainerContext) Label(name string) string
Label returns the value of the label with the given name or an empty string if the given label does not exist.
func (*ContainerContext) Labels ¶
func (c *ContainerContext) Labels() string
Labels returns a comma-separated string of labels present on the container.
func (*ContainerContext) LocalVolumes ¶
func (c *ContainerContext) LocalVolumes() string
LocalVolumes returns the number of volumes using the "local" volume driver.
func (*ContainerContext) MarshalJSON ¶
func (c *ContainerContext) MarshalJSON() ([]byte, error)
MarshalJSON makes ContainerContext implement json.Marshaler
func (*ContainerContext) Mounts ¶
func (c *ContainerContext) Mounts() string
Mounts returns a comma-separated string of mount names present on the container. If the trunc option is set, names can be truncated (ellipsized).
func (*ContainerContext) Names ¶
func (c *ContainerContext) Names() string
Names returns a comma-separated string of the container's names, with their slash (/) prefix stripped. Additional names for the container (related to the legacy `--link` feature) are omitted.
func (*ContainerContext) Networks ¶
func (c *ContainerContext) Networks() string
Networks returns a comma-separated string of networks that the container is attached to.
func (*ContainerContext) Ports ¶
func (c *ContainerContext) Ports() string
Ports returns a comma-separated string representing open ports of the container e.g. "0.0.0.0:80->9090/tcp, 9988/tcp" it's used by command 'docker ps' Both published and exposed ports are included.
func (*ContainerContext) RunningFor ¶
func (c *ContainerContext) RunningFor() string
RunningFor returns a human-readable representation of the duration for which the container has been running.
Note that this duration is calculated on the client, and as such is influenced by clock skew between the client and the daemon.
func (*ContainerContext) Size ¶
func (c *ContainerContext) Size() string
Size returns the container's size and virtual size (e.g. "2B (virtual 21.5MB)")
func (*ContainerContext) State ¶
func (c *ContainerContext) State() string
State returns the container's current state (e.g. "running" or "paused")
func (*ContainerContext) Status ¶
func (c *ContainerContext) Status() string
Status returns the container's status in a human readable form (for example, "Up 24 hours" or "Exited (0) 8 days ago")
type Context ¶
type Context struct { // Output is the output stream to which the formatted string is written. Output io.Writer // Format is used to choose raw, table or custom format for the output. Format Format // Trunc when set to true will truncate the output of certain fields such as Container ID. Trunc bool // contains filtered or unexported fields }
Context contains information required by the formatter to print the output as desired.
type DiskUsageContext ¶
type DiskUsageContext struct { Context Verbose bool LayersSize int64 Images []*types.ImageSummary Containers []*types.Container Volumes []*volume.Volume BuildCache []*types.BuildCache BuilderSize int64 }
DiskUsageContext contains disk usage specific information required by the formatter, encapsulate a Context struct.
func (*DiskUsageContext) Write ¶
func (ctx *DiskUsageContext) Write() (err error)
type Format ¶
type Format string
Format is the format string rendered using the Context
func NewBuildCacheFormat ¶
NewBuildCacheFormat returns a Format for rendering using a Context
func NewClientContextFormat ¶
NewClientContextFormat returns a Format for rendering using a Context
func NewContainerFormat ¶
NewContainerFormat returns a Format for rendering using a Context
func NewDiskUsageFormat ¶
NewDiskUsageFormat returns a format for rendering an DiskUsageContext
func NewImageFormat ¶
NewImageFormat returns a format for rendering an ImageContext
func NewVolumeFormat ¶
NewVolumeFormat returns a format for use with a volume Context
type HeaderContext ¶
type HeaderContext struct {
Header interface{}
}
HeaderContext provides the subContext interface for managing headers
func (*HeaderContext) FullHeader ¶
func (c *HeaderContext) FullHeader() interface{}
FullHeader returns the header as an interface
type ImageContext ¶
ImageContext contains image specific information required by the formatter, encapsulate a Context struct.
type SubContext ¶
type SubContext interface {
FullHeader() interface{}
}
SubContext defines what Context implementation should provide
type SubFormat ¶
type SubFormat func(func(SubContext) error) error
SubFormat is a function type accepted by Write()
type SubHeaderContext ¶
SubHeaderContext is a map destined to formatter header (table format)
func (SubHeaderContext) Label ¶
func (c SubHeaderContext) Label(name string) string
Label returns the header label for the specified string