formatter

package
v20.10.19+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2022 License: Apache-2.0 Imports: 20 Imported by: 2,354

Documentation

Index

Constants

View Source
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"
	ContainerIDHeader  = "CONTAINER ID"
)

Common header constants

View Source
const (
	TableFormatKey  = "table"
	RawFormatKey    = "raw"
	PrettyFormatKey = "pretty"

	DefaultQuietFormat = "{{.ID}}"
)

Format keys used to specify certain kinds of output formats

View Source
const (
	// ClientContextTableFormat is the default client context format
	ClientContextTableFormat = "" /* 127-byte string literal not displayed */

)

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

func ContainerWrite(ctx Context, containers []types.Container) error

ContainerWrite renders the context for a list of containers

func DisplayablePorts

func DisplayablePorts(ports []types.Port) string

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

func Ellipsis(s string, maxDisplayWidth int) string

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

func MarshalJSON(x interface{}) ([]byte, error)

MarshalJSON marshals x into json It differs a bit from encoding/json MarshalJSON function for formatter

func VolumeWrite

func VolumeWrite(ctx Context, volumes []*types.Volume) error

VolumeWrite writes formatted volumes using the Context

Types

type ClientContext

type ClientContext struct {
	Name               string
	Description        string
	DockerEndpoint     string
	KubernetesEndpoint string
	StackOrchestrator  string
	Current            bool
}

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.