move: add --delete-empty-src-dirs flag - fixes #1854

This commit is contained in:
ishuah
2017-11-27 14:42:02 +03:00
committed by Ishuah Kariuki
parent 1248beb0b2
commit aab8051f50
5 changed files with 84 additions and 43 deletions

View File

@ -6,8 +6,14 @@ import (
"github.com/spf13/cobra"
)
// Globals
var (
deleteEmptySrcDirs = false
)
func init() {
cmd.Root.AddCommand(commandDefintion)
commandDefintion.Flags().BoolVarP(&deleteEmptySrcDirs, "delete-empty-src-dirs", "", deleteEmptySrcDirs, "Delete empty source dirs after move")
}
var commandDefintion = &cobra.Command{
@ -28,6 +34,8 @@ move will be used, otherwise it will copy it (server side if possible)
into ` + "`dest:path`" + ` then delete the original (if no errors on copy) in
` + "`source:path`" + `.
If you want to delete empty source directories after move, use the --delete-empty-src-dirs flag.
**Important**: Since this can cause data loss, test first with the
--dry-run flag.
`,
@ -35,7 +43,8 @@ into ` + "`dest:path`" + ` then delete the original (if no errors on copy) in
cmd.CheckArgs(2, 2, command, args)
fsrc, fdst := cmd.NewFsSrcDst(args)
cmd.Run(true, true, command, func() error {
return fs.MoveDir(fdst, fsrc)
return fs.MoveDir(fdst, fsrc, deleteEmptySrcDirs)
})
},
}