Commits

Paul Ruane committed 795b5eb

Improved output of 'dupes' command and fixed bug with empty file set.
Fixed bug in 'tags' command when no argument specified.
Fixed bug in 'tag' command which erroneously report files as duplicates.

Comments (0)

Files changed (4)

src/main/commands/dupes.go

     for index, fileSet := range fileSets {
         if index > 0 { fmt.Println() }
 
+        fmt.Printf("%v duplicate files:\n", len(fileSet))
+
         for _, file := range fileSet {
-            fmt.Println(file.Path)
+            fmt.Printf("  %v\n", file.Path)
         }
     }
 

src/main/commands/tag.go

 		files, error := db.FilesByFingerprint(fingerprint)
 		if error != nil { return nil, error }
 
-		if files != nil {
-			fmt.Printf("Warning: file is a duplicate of a previously tagged file.\n")
+		if len(files) > 0 {
+			fmt.Printf("Warning: file is a duplicate of previously tagged files.\n")
+
+			for _, duplicateFile := range files {
+			    fmt.Printf("  %v\n", duplicateFile.Path)
+            }
 		}
 
 		file, error = db.AddFile(path, fingerprint)

src/main/commands/tags.go

 }
 
 func (this TagsCommand) Summary() string {
-	return "lists all tags or tags applied to a file or files"
+	return "lists all tags or tags applied to files"
 }
 
 func (this TagsCommand) Help() string {
 	return `  tmsu tags --all
   tmsu tags [FILE]...
 
-Lists the tags applied to FILEs (the current directory by default).
+Lists the tags applied to FILEs (files in the current directory by default).
 
   --all    show the complete set of tags`
 }
 func (this TagsCommand) Exec(args []string) error {
     argCount := len(args)
 
-    if argCount == 0 {
-        return this.listTags(".")
-    } else if argCount == 1 && args[0] == "--all" {
+    if argCount == 1 && args[0] == "--all" {
         return this.listAllTags()
     } else {
 	    this.listTags(args...)
 	if error != nil { return error }
 	defer db.Close()
 
-    if len(paths) == 1 {
-        tags, error := this.tagsForPath(db, paths[0])
-        if error != nil { return error }
-        if tags == nil { return nil }
-
-        for _, tag := range tags {
-            fmt.Println(tag.Name)
-        }
-
-        return nil
+    switch len(paths) {
+        case 0:
+            return this.listTagsRecursive(db, []string { "." })
+        case 1:
+            return this.listTagsForPath(db, paths[0])
+        default:
+            return this.listTagsRecursive(db, paths)
     }
 
     return this.listTagsRecursive(db, paths)
 }
 
+func (this TagsCommand) listTagsForPath(db *Database, path string) error {
+    tags, error := this.tagsForPath(db, path)
+    if error != nil { return error }
+
+    for _, tag := range tags {
+        fmt.Println(tag.Name)
+    }
+
+    return nil
+}
+
 func (this TagsCommand) listTagsRecursive(db *Database, paths []string) error {
     for _, path := range paths {
         fileInfo, error := os.Lstat(path)

src/main/database.go

 	}
 
     // ensure last file set is added
-    fileSets = append(fileSets, fileSet)
+    if len(fileSet) > 0 { fileSets = append(fileSets, fileSet) }
 
 	return fileSets, nil
 }