From 38adb35abe2574b757eae8b06ba769c5b9771c3f Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 3 Aug 2016 18:00:25 +0100 Subject: [PATCH] Make dedupe take an optional mode parameter --- docs/content/docs.md | 4 ++++ rclone.go | 25 +++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/docs/content/docs.md b/docs/content/docs.md index 9c34981bf..641730989 100644 --- a/docs/content/docs.md +++ b/docs/content/docs.md @@ -283,6 +283,10 @@ For example to rename all the identically named photos in your Google Photos dir rclone dedupe --dedupe-mode rename "drive:Google Photos" +The modes can also be passed as an extra parameter, eg + + rclone dedupe rename "drive:Google Photos" + ### rclone config ### Enter an interactive configuration session. diff --git a/rclone.go b/rclone.go index 07718f563..f1e4ede08 100644 --- a/rclone.go +++ b/rclone.go @@ -438,15 +438,32 @@ don't match. It doesn't alter the source or destination.`, } var dedupeCmd = &cobra.Command{ - Use: "dedupe remote:path", + Use: "dedupe [mode] remote:path", Short: `Interactively find duplicate files delete/rename them.`, Long: ` Interactively find duplicate files and offer to delete all but one or rename them to be different. Only useful with -Google Drive which can have duplicate file names.`, +Google Drive which can have duplicate file names. + +Pass in an extra parameter to make the dedupe noninteractive + + interactive - interactive as above. + skip - removes identical files then skips anything left. + first - removes identical files then keeps the first one. + newest - removes identical files then keeps the newest one. + oldest - removes identical files then keeps the oldest one. + rename - removes identical files then renames the rest to be different. +`, Run: func(cmd *cobra.Command, args []string) { - checkArgs(1, 1, cmd, args) - fdst := NewFsSrc(args[1]) + checkArgs(1, 2, cmd, args) + if len(args) > 1 { + err := dedupeMode.Set(args[0]) + if err != nil { + log.Fatal(err) + } + args = args[1:] + } + fdst := newFsSrc(args) run(false, cmd, func() error { return fs.Deduplicate(fdst, dedupeMode) })