2016-05-12 10:52:00 -04:00
|
|
|
package checkpoint
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
2016-05-12 10:52:00 -04:00
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli"
|
|
|
|
"github.com/docker/cli/cli/command"
|
2022-03-30 09:27:25 -04:00
|
|
|
"github.com/docker/cli/cli/command/completion"
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/command/formatter"
|
2023-08-28 06:06:35 -04:00
|
|
|
"github.com/docker/docker/api/types/checkpoint"
|
2016-05-12 10:52:00 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2016-09-19 12:01:16 -04:00
|
|
|
type listOptions struct {
|
|
|
|
checkpointDir string
|
|
|
|
}
|
|
|
|
|
2017-05-03 17:58:52 -04:00
|
|
|
func newListCommand(dockerCli command.Cli) *cobra.Command {
|
2016-09-19 12:01:16 -04:00
|
|
|
var opts listOptions
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
2016-11-08 03:15:09 -05:00
|
|
|
Use: "ls [OPTIONS] CONTAINER",
|
2016-05-12 10:52:00 -04:00
|
|
|
Aliases: []string{"list"},
|
|
|
|
Short: "List checkpoints for a container",
|
|
|
|
Args: cli.ExactArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2023-09-09 18:27:44 -04:00
|
|
|
return runList(cmd.Context(), dockerCli, args[0], opts)
|
2016-05-12 10:52:00 -04:00
|
|
|
},
|
2022-03-30 09:27:25 -04:00
|
|
|
ValidArgsFunction: completion.ContainerNames(dockerCli, false),
|
2016-05-12 10:52:00 -04:00
|
|
|
}
|
2016-09-19 12:01:16 -04:00
|
|
|
|
|
|
|
flags := cmd.Flags()
|
2016-11-08 03:15:09 -05:00
|
|
|
flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "Use a custom checkpoint storage directory")
|
2016-09-19 12:01:16 -04:00
|
|
|
|
|
|
|
return cmd
|
2016-05-12 10:52:00 -04:00
|
|
|
}
|
|
|
|
|
2023-09-09 18:27:44 -04:00
|
|
|
func runList(ctx context.Context, dockerCli command.Cli, container string, opts listOptions) error {
|
|
|
|
checkpoints, err := dockerCli.Client().CheckpointList(ctx, container, checkpoint.ListOptions{
|
2016-09-19 12:01:16 -04:00
|
|
|
CheckpointDir: opts.checkpointDir,
|
2023-08-28 06:06:35 -04:00
|
|
|
})
|
2016-05-12 10:52:00 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-03-13 17:19:46 -04:00
|
|
|
cpCtx := formatter.Context{
|
|
|
|
Output: dockerCli.Out(),
|
2018-10-23 11:05:44 -04:00
|
|
|
Format: NewFormat(formatter.TableFormatKey),
|
2016-05-12 10:52:00 -04:00
|
|
|
}
|
2018-10-23 11:05:44 -04:00
|
|
|
return FormatWrite(cpCtx, checkpoints)
|
2016-05-12 10:52:00 -04:00
|
|
|
}
|