remove.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package checkpoint
  2. import (
  3. "golang.org/x/net/context"
  4. "github.com/docker/docker/api/types"
  5. "github.com/docker/docker/cli"
  6. "github.com/docker/docker/cli/command"
  7. "github.com/spf13/cobra"
  8. )
  9. type removeOptions struct {
  10. checkpointDir string
  11. }
  12. func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
  13. var opts removeOptions
  14. cmd := &cobra.Command{
  15. Use: "rm [OPTIONS] CONTAINER CHECKPOINT",
  16. Aliases: []string{"remove"},
  17. Short: "Remove a checkpoint",
  18. Args: cli.ExactArgs(2),
  19. RunE: func(cmd *cobra.Command, args []string) error {
  20. return runRemove(dockerCli, args[0], args[1], opts)
  21. },
  22. }
  23. flags := cmd.Flags()
  24. flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "Use a custom checkpoint storage directory")
  25. return cmd
  26. }
  27. func runRemove(dockerCli *command.DockerCli, container string, checkpoint string, opts removeOptions) error {
  28. client := dockerCli.Client()
  29. removeOpts := types.CheckpointDeleteOptions{
  30. CheckpointID: checkpoint,
  31. CheckpointDir: opts.checkpointDir,
  32. }
  33. return client.CheckpointDelete(context.Background(), container, removeOpts)
  34. }