formatter

package
v0.0.0-...-896ff57 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 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"
	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 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