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"
|
|
|
|
"github.com/docker/cli/cli/command/formatter"
|
2016-09-19 12:01:16 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
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 {
|
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
|
|
|
}
|
|
|
|
|
2017-05-03 17:58:52 -04:00
|
|
|
func runList(dockerCli command.Cli, 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(),
|
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
|
|
|
}
|