2016-05-12 10:52:00 -04:00
|
|
|
package checkpoint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2016-09-19 12:01:16 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2016-05-12 10:52:00 -04:00
|
|
|
"github.com/docker/docker/cli"
|
|
|
|
"github.com/docker/docker/cli/command"
|
2017-03-13 17:19:46 -04:00
|
|
|
"github.com/docker/docker/cli/command/formatter"
|
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
|
|
|
|
}
|
|
|
|
|
2016-05-12 10:52:00 -04:00
|
|
|
func newListCommand(dockerCli *command.DockerCli) *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 {
|
2016-09-19 12:01:16 -04:00
|
|
|
return runList(dockerCli, args[0], opts)
|
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
|
|
|
}
|
|
|
|
|
2016-09-19 12:01:16 -04:00
|
|
|
func runList(dockerCli *command.DockerCli, container string, opts listOptions) error {
|
2016-05-12 10:52:00 -04:00
|
|
|
client := dockerCli.Client()
|
|
|
|
|
2016-09-19 12:01:16 -04:00
|
|
|
listOpts := types.CheckpointListOptions{
|
|
|
|
CheckpointDir: opts.checkpointDir,
|
|
|
|
}
|
|
|
|
|
|
|
|
checkpoints, err := client.CheckpointList(context.Background(), container, listOpts)
|
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(),
|
|
|
|
Format: formatter.NewCheckpointFormat(formatter.TableFormatKey),
|
2016-05-12 10:52:00 -04:00
|
|
|
}
|
2017-03-13 17:19:46 -04:00
|
|
|
return formatter.CheckpointWrite(cpCtx, checkpoints)
|
2016-05-12 10:52:00 -04:00
|
|
|
}
|