Files
docker-cli/cli/command/checkpoint/formatter.go
Sebastiaan van Stijn e416418e70 cli/command/checkpoint: remove deprecated formatting functions
These were deprecated in d861b78a8a, which
is part of the v28.4 release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-22 09:34:17 +02:00

54 lines
1.3 KiB
Go

package checkpoint
import (
"github.com/docker/cli/cli/command/formatter"
"github.com/moby/moby/api/types/checkpoint"
)
const (
defaultCheckpointFormat = "table {{.Name}}"
checkpointNameHeader = "CHECKPOINT NAME"
)
// newFormat returns a format for use with a checkpointContext.
func newFormat(source string) formatter.Format {
if source == formatter.TableFormatKey {
return defaultCheckpointFormat
}
return formatter.Format(source)
}
// formatWrite writes formatted checkpoints using the Context
func formatWrite(fmtCtx formatter.Context, checkpoints []checkpoint.Summary) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, cp := range checkpoints {
if err := format(&checkpointContext{c: cp}); err != nil {
return err
}
}
return nil
}
return fmtCtx.Write(newCheckpointContext(), render)
}
type checkpointContext struct {
formatter.HeaderContext
c checkpoint.Summary
}
func newCheckpointContext() *checkpointContext {
cpCtx := checkpointContext{}
cpCtx.Header = formatter.SubHeaderContext{
"Name": checkpointNameHeader,
}
return &cpCtx
}
func (c *checkpointContext) MarshalJSON() ([]byte, error) {
return formatter.MarshalJSON(c)
}
func (c *checkpointContext) Name() string {
return c.c.Name
}