2016-05-12 10:52:00 -04:00
|
|
|
package checkpoint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"text/tabwriter"
|
|
|
|
|
|
|
|
"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"
|
|
|
|
"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-05-12 10:52:00 -04:00
|
|
|
Use: "ls CONTAINER",
|
|
|
|
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()
|
|
|
|
flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "use a custom checkpoint storage directory")
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
w := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 3, ' ', 0)
|
|
|
|
fmt.Fprintf(w, "CHECKPOINT NAME")
|
|
|
|
fmt.Fprintf(w, "\n")
|
|
|
|
|
|
|
|
for _, checkpoint := range checkpoints {
|
|
|
|
fmt.Fprintf(w, "%s\t", checkpoint.Name)
|
|
|
|
fmt.Fprint(w, "\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
w.Flush()
|
|
|
|
return nil
|
|
|
|
}
|