purge.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Package purge provides the purge command.
  2. package purge
  3. import (
  4. "context"
  5. "github.com/rclone/rclone/cmd"
  6. "github.com/rclone/rclone/fs/operations"
  7. "github.com/spf13/cobra"
  8. )
  9. func init() {
  10. cmd.Root.AddCommand(commandDefinition)
  11. }
  12. var commandDefinition = &cobra.Command{
  13. Use: "purge remote:path",
  14. Short: `Remove the path and all of its contents.`,
  15. Long: `
  16. Remove the path and all of its contents. Note that this does not obey
  17. include/exclude filters - everything will be removed. Use the
  18. [delete](/commands/rclone_delete/) command if you want to selectively
  19. delete files. To delete empty directories only, use command
  20. [rmdir](/commands/rclone_rmdir/) or [rmdirs](/commands/rclone_rmdirs/).
  21. **Important**: Since this can cause data loss, test first with the
  22. ` + "`--dry-run` or the `--interactive`/`-i`" + ` flag.
  23. `,
  24. Annotations: map[string]string{
  25. "groups": "Important",
  26. },
  27. Run: func(command *cobra.Command, args []string) {
  28. cmd.CheckArgs(1, 1, command, args)
  29. fdst := cmd.NewFsDir(args)
  30. cmd.Run(true, false, command, func() error {
  31. return operations.Purge(context.Background(), fdst, "")
  32. })
  33. },
  34. }