formatter

package
v20.10.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

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.

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.

func (*Context) Write

func (c *Context) Write(sub SubContext, f SubFormat) error

Write the template to the buffer using this Context

type DiskUsageContext

type DiskUsageContext struct {
	Context
	Verbose     bool
	LayersSize  int64
	Images      []*types.ImageSummary
	Containers  []*types.Container
	Volumes     []*types.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

func NewBuildCacheFormat(source string, quiet bool) Format

NewBuildCacheFormat returns a Format for rendering using a Context

func NewClientContextFormat

func NewClientContextFormat(source string, quiet bool) Format

NewClientContextFormat returns a Format for rendering using a Context

func NewContainerFormat

func NewContainerFormat(source string, quiet bool, size bool) Format

NewContainerFormat returns a Format for rendering using a Context

func NewDiskUsageFormat

func NewDiskUsageFormat(source string, verbose bool) Format

NewDiskUsageFormat returns a format for rendering an DiskUsageContext

func NewImageFormat

func NewImageFormat(source string, quiet bool, digest bool) Format

NewImageFormat returns a format for rendering an ImageContext

func NewVolumeFormat

func NewVolumeFormat(source string, quiet bool) Format

NewVolumeFormat returns a format for use with a volume Context

func (Format) Contains

func (f Format) Contains(sub string) bool

Contains returns true if the format contains the substring

func (Format) IsTable

func (f Format) IsTable() bool

IsTable returns true if the format is a table-type format

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

type ImageContext struct {
	Context
	Digest bool
}

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

type SubHeaderContext map[string]string

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL