{"modulePath":"github.com/xpippi/docker-cli","version":"v23.0.3+incompatible","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package formatter\n\n## Constants\n\n```go\nconst (\n\tCreatedSinceHeader = \"CREATED\"\n\tCreatedAtHeader    = \"CREATED AT\"\n\tSizeHeader         = \"SIZE\"\n\tLabelsHeader       = \"LABELS\"\n\tNameHeader         = \"NAME\"\n\tDescriptionHeader  = \"DESCRIPTION\"\n\tDriverHeader       = \"DRIVER\"\n\tScopeHeader        = \"SCOPE\"\n\tStateHeader        = \"STATE\"\n\tStatusHeader       = \"STATUS\"\n\tPortsHeader        = \"PORTS\"\n\tImageHeader        = \"IMAGE\"\n\tErrorHeader        = \"ERROR\"\n\tContainerIDHeader  = \"CONTAINER ID\"\n)\n```\nCommon header constants\n\n```go\nconst (\n\tTableFormatKey  = \"table\"\n\tRawFormatKey    = \"raw\"\n\tPrettyFormatKey = \"pretty\"\n\tJSONFormatKey   = \"json\"\n\n\tDefaultQuietFormat = \"{{.ID}}\"\n)\n```\nFormat keys used to specify certain kinds of output formats\n\n```go\nconst (\n\t// ClientContextTableFormat is the default client context format.\n\tClientContextTableFormat = \"table {{.Name}}{{if .Current}} *{{end}}\\t{{.Description}}\\t{{.DockerEndpoint}}\\t{{.Error}}\"\n)\n```\n\n## Functions\n\n```go\nfunc BuildCacheWrite(ctx Context, buildCaches []*types.BuildCache) error\n```\nBuildCacheWrite renders the context for a list of containers\n\n```go\nfunc ClientContextWrite(ctx Context, contexts []*ClientContext) error\n```\nClientContextWrite writes formatted contexts using the Context\n\n```go\nfunc ContainerWrite(ctx Context, containers []types.Container) error\n```\nContainerWrite renders the context for a list of containers\n\n```go\nfunc DisplayablePorts(ports []types.Port) string\n```\nDisplayablePorts returns formatted string representing open ports of container e.g. \"0.0.0.0:80-\u003e9090/tcp, 9988/tcp\" it's used by command 'docker ps'\n\n```go\nfunc Ellipsis(s string, maxDisplayWidth int) string\n```\nEllipsis 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 \u003e 1.\n\n```go\nfunc ImageWrite(ctx ImageContext, images []types.ImageSummary) error\n```\nImageWrite writes the formatter images using the ImageContext\n\n```go\nfunc MarshalJSON(x interface{}) ([]byte, error)\n```\nMarshalJSON marshals x into json It differs a bit from encoding/json MarshalJSON function for formatter\n\n```go\nfunc StripNamePrefix(ss []string) []string\n```\nStripNamePrefix removes prefix from string, typically container names as returned by \\`ContainersList\\` API\n\n```go\nfunc VolumeWrite(ctx Context, volumes []*volume.Volume) error\n```\nVolumeWrite writes formatted volumes using the Context\n\n## Types\n\n```go\ntype ClientContext struct {\n\tName           string\n\tDescription    string\n\tDockerEndpoint string\n\tCurrent        bool\n\tError          string\n}\n```\nClientContext is a context for display\n\n```go\ntype ContainerContext struct {\n\tHeaderContext\n\n\t// FieldsUsed is used in the pre-processing step to detect which fields are\n\t// used in the template. It's currently only used to detect use of the .Size\n\t// field which (if used) automatically sets the '--size' option when making\n\t// the API call.\n\tFieldsUsed map[string]interface{}\n\t// contains filtered or unexported fields\n}\n```\nContainerContext is a struct used for rendering a list of containers in a Go template.\n\n```go\nfunc NewContainerContext() *ContainerContext\n```\nNewContainerContext creates a new context for rendering containers\n\n```go\nfunc (c *ContainerContext) Command() string\n```\nCommand returns's the container's command. If the trunc option is set, the returned command is truncated (ellipsized).\n\n```go\nfunc (c *ContainerContext) CreatedAt() string\n```\nCreatedAt returns the \"Created\" date/time of the container as a unix timestamp.\n\n```go\nfunc (c *ContainerContext) ID() string\n```\nID returns the container's ID as a string. Depending on the \\`--no-trunc\\` option being set, the full or truncated ID is returned.\n\n```go\nfunc (c *ContainerContext) Image() string\n```\nImage returns the container's image reference. If the trunc option is set, the image's registry digest can be included.\n\n```go\nfunc (c *ContainerContext) Label(name string) string\n```\nLabel returns the value of the label with the given name or an empty string if the given label does not exist.\n\n```go\nfunc (c *ContainerContext) Labels() string\n```\nLabels returns a comma-separated string of labels present on the container.\n\n```go\nfunc (c *ContainerContext) LocalVolumes() string\n```\nLocalVolumes returns the number of volumes using the \"local\" volume driver.\n\n```go\nfunc (c *ContainerContext) MarshalJSON() ([]byte, error)\n```\nMarshalJSON makes ContainerContext implement json.Marshaler\n\n```go\nfunc (c *ContainerContext) Mounts() string\n```\nMounts returns a comma-separated string of mount names present on the container. If the trunc option is set, names can be truncated (ellipsized).\n\n```go\nfunc (c *ContainerContext) Names() string\n```\nNames 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.\n\n```go\nfunc (c *ContainerContext) Networks() string\n```\nNetworks returns a comma-separated string of networks that the container is attached to.\n\n```go\nfunc (c *ContainerContext) Ports() string\n```\nPorts returns a comma-separated string representing open ports of the container e.g. \"0.0.0.0:80-\u003e9090/tcp, 9988/tcp\" it's used by command 'docker ps' Both published and exposed ports are included.\n\n```go\nfunc (c *ContainerContext) RunningFor() string\n```\nRunningFor returns a human-readable representation of the duration for which the container has been running.\n\nNote that this duration is calculated on the client, and as such is influenced by clock skew between the client and the daemon.\n\n```go\nfunc (c *ContainerContext) Size() string\n```\nSize returns the container's size and virtual size (e.g. \"2B (virtual 21.5MB)\")\n\n```go\nfunc (c *ContainerContext) State() string\n```\nState returns the container's current state (e.g. \"running\" or \"paused\")\n\n```go\nfunc (c *ContainerContext) Status() string\n```\nStatus returns the container's status in a human readable form (for example, \"Up 24 hours\" or \"Exited (0) 8 days ago\")\n\n```go\ntype Context struct {\n\t// Output is the output stream to which the formatted string is written.\n\tOutput io.Writer\n\t// Format is used to choose raw, table or custom format for the output.\n\tFormat Format\n\t// Trunc when set to true will truncate the output of certain fields such as Container ID.\n\tTrunc bool\n\t// contains filtered or unexported fields\n}\n```\nContext contains information required by the formatter to print the output as desired.\n\n```go\nfunc (c *Context) Write(sub SubContext, f SubFormat) error\n```\nWrite the template to the buffer using this Context\n\n```go\ntype DiskUsageContext struct {\n\tContext\n\tVerbose     bool\n\tLayersSize  int64\n\tImages      []*types.ImageSummary\n\tContainers  []*types.Container\n\tVolumes     []*volume.Volume\n\tBuildCache  []*types.BuildCache\n\tBuilderSize int64\n}\n```\nDiskUsageContext contains disk usage specific information required by the formatter, encapsulate a Context struct.\n\n```go\nfunc (ctx *DiskUsageContext) Write() (err error)\n```\n\n```go\ntype Format string\n```\nFormat is the format string rendered using the Context\n\n```go\nfunc NewBuildCacheFormat(source string, quiet bool) Format\n```\nNewBuildCacheFormat returns a Format for rendering using a Context\n\n```go\nfunc NewClientContextFormat(source string, quiet bool) Format\n```\nNewClientContextFormat returns a Format for rendering using a Context\n\n```go\nfunc NewContainerFormat(source string, quiet bool, size bool) Format\n```\nNewContainerFormat returns a Format for rendering using a Context\n\n```go\nfunc NewDiskUsageFormat(source string, verbose bool) Format\n```\nNewDiskUsageFormat returns a format for rendering an DiskUsageContext\n\n```go\nfunc NewImageFormat(source string, quiet bool, digest bool) Format\n```\nNewImageFormat returns a format for rendering an ImageContext\n\n```go\nfunc NewVolumeFormat(source string, quiet bool) Format\n```\nNewVolumeFormat returns a format for use with a volume Context\n\n```go\nfunc (f Format) Contains(sub string) bool\n```\nContains returns true if the format contains the substring\n\n```go\nfunc (f Format) IsJSON() bool\n```\nIsJSON returns true if the format is the json format\n\n```go\nfunc (f Format) IsTable() bool\n```\nIsTable returns true if the format is a table-type format\n\n```go\ntype HeaderContext struct {\n\tHeader interface{}\n}\n```\nHeaderContext provides the subContext interface for managing headers\n\n```go\nfunc (c *HeaderContext) FullHeader() interface{}\n```\nFullHeader returns the header as an interface\n\n```go\ntype ImageContext struct {\n\tContext\n\tDigest bool\n}\n```\nImageContext contains image specific information required by the formatter, encapsulate a Context struct.\n\n```go\ntype SubContext interface {\n\tFullHeader() interface{}\n}\n```\nSubContext defines what Context implementation should provide\n\n```go\ntype SubFormat func(func(SubContext) error) error\n```\nSubFormat is a function type accepted by Write()\n\n```go\ntype SubHeaderContext map[string]string\n```\nSubHeaderContext is a map destined to formatter header (table format)\n\n```go\nfunc (c SubHeaderContext) Label(name string) string\n```\nLabel returns the header label for the specified string\n\n","path":"github.com/xpippi/docker-cli/cli/command/formatter","name":"formatter","synopsis":"","isRedistributable":true}
