github.1git.de/docker/cli@v26.1.3+incompatible/cli/command/checkpoint/list.go (about)

     1  package checkpoint
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/docker/cli/cli"
     7  	"github.com/docker/cli/cli/command"
     8  	"github.com/docker/cli/cli/command/completion"
     9  	"github.com/docker/cli/cli/command/formatter"
    10  	"github.com/docker/docker/api/types/checkpoint"
    11  	"github.com/spf13/cobra"
    12  )
    13  
    14  type listOptions struct {
    15  	checkpointDir string
    16  }
    17  
    18  func newListCommand(dockerCli command.Cli) *cobra.Command {
    19  	var opts listOptions
    20  
    21  	cmd := &cobra.Command{
    22  		Use:     "ls [OPTIONS] CONTAINER",
    23  		Aliases: []string{"list"},
    24  		Short:   "List checkpoints for a container",
    25  		Args:    cli.ExactArgs(1),
    26  		RunE: func(cmd *cobra.Command, args []string) error {
    27  			return runList(cmd.Context(), dockerCli, args[0], opts)
    28  		},
    29  		ValidArgsFunction: completion.ContainerNames(dockerCli, false),
    30  	}
    31  
    32  	flags := cmd.Flags()
    33  	flags.StringVar(&opts.checkpointDir, "checkpoint-dir", "", "Use a custom checkpoint storage directory")
    34  
    35  	return cmd
    36  }
    37  
    38  func runList(ctx context.Context, dockerCli command.Cli, container string, opts listOptions) error {
    39  	checkpoints, err := dockerCli.Client().CheckpointList(ctx, container, checkpoint.ListOptions{
    40  		CheckpointDir: opts.checkpointDir,
    41  	})
    42  	if err != nil {
    43  		return err
    44  	}
    45  
    46  	cpCtx := formatter.Context{
    47  		Output: dockerCli.Out(),
    48  		Format: NewFormat(formatter.TableFormatKey),
    49  	}
    50  	return FormatWrite(cpCtx, checkpoints)
    51  }