Commits

Paul Ruane  committed dcb09c2

Added --count option to 'tags' command to list tag counts rather than tags.

  • Participants
  • Parent commits 4ac2a20

Comments (0)

Files changed (2)

File misc/zsh/_tmsu

 
 _tmsu_cmd_tags() {
 	_arguments -s -w ''{--all,-a}'[show all tags]' \
+	                 ''{--count,-c}'[lists the tag count]' \
 	                 '*:file:_files' \
 	&& ret=0
 }

File src/tmsu/cli/commands/tags.go

 	"fmt"
 	"os"
 	"sort"
+	"strconv"
 	"strings"
 	"tmsu/cli"
 	"tmsu/log"
 
 type TagsCommand struct {
 	verbose bool
+	count   bool
 }
 
 func (TagsCommand) Name() cli.CommandName {
 }
 
 func (TagsCommand) Options() cli.Options {
-	return cli.Options{{"--all", "-a", "lists all of the tags defined", false, ""}}
+	return cli.Options{{"--all", "-a", "lists all of the tags defined", false, ""},
+		{"--count", "-c", "lists the tag count", false, ""}}
 }
 
 func (command TagsCommand) Exec(options cli.Options, args []string) error {
 	command.verbose = options.HasOption("--verbose")
+	command.count = options.HasOption("--count")
 
 	if options.HasOption("--all") {
 		return command.listAllTags()
 		}
 	}
 
-	for _, tag := range tags {
-		log.Print(tag.Name)
+	if command.count {
+		log.Print(len(tags))
+	} else {
+		for _, tag := range tags {
+			log.Print(tag.Name)
+		}
 	}
 
 	return nil
 		}
 
 		var tags, err = store.TagsForPath(path)
-
 		if err != nil {
 			log.Warn(err.Error())
 			continue
 		}
 
-		log.Print(path + ": " + tagLine(tags))
+		if command.count {
+			log.Print(path + ": " + strconv.Itoa(len(tags)))
+		} else {
+			log.Print(path + ": " + tagLine(tags))
+		}
 	}
 
 	return nil
 			continue
 		}
 
-		log.Print(dirName + ": " + tagLine(tags))
+		if command.count {
+			log.Print(dirName + ": " + strconv.Itoa(len(tags)))
+		} else {
+			log.Print(dirName + ": " + tagLine(tags))
+		}
 	}
 
 	return nil