Commits

Paul Ruane  committed 9b4088a

Added --untagged option to 'status' command.

  • Participants
  • Parent commits 3a139a8

Comments (0)

Files changed (2)

File misc/zsh/_tmsu

 
 _tmsu_cmd_status() {
 	_arguments -s -w ''{--directory,-d}'[list directory entries only: do not list contents]' \
+	                 ''{--untagged,-u}'[list untagged entries only]' \
 	                 '*:file:_files' \
 	&& ret=0
 }

File src/tmsu/cli/status.go

 
     $ tmsu status
     $ tmsu status .
-    $ tmsu status --directory *`,
-	Options: Options{Option{"--directory", "-d", "list directory entries only: do not list contents", false, ""}},
-	Exec:    statusExec,
+    $ tmsu status --directory *
+    $ tmsu status --untagged`,
+	Options: Options{Option{"--directory", "-d", "list directory entries only: do not list contents", false, ""},
+		{"--untagged", "-u", "list only untagged files", false, ""}},
+	Exec: statusExec,
 }
 
 type Status byte
 
 func statusExec(options Options, args []string) error {
 	dirOnly := options.HasOption("--directory")
+	untaggedOnly := options.HasOption("--untagged")
 
 	var report *StatusReport
 	var err error
 
 	if len(args) == 0 {
+		if untaggedOnly {
+			// untagged files are not retained in the database
+			return nil
+		}
+
 		report, err = statusDatabase(dirOnly)
 		if err != nil {
 			return err
 		}
 	}
 
-	printReport(report)
+	printReport(report, untaggedOnly)
 
 	return nil
 }
 	return nil
 }
 
-func printReport(report *StatusReport) {
-	for _, row := range report.Rows {
-		if row.Status == TAGGED {
-			printRow(row)
-		}
+func printReport(report *StatusReport, untaggedOnly bool) {
+	if !untaggedOnly {
+		printRows(report.Rows, TAGGED)
+		printRows(report.Rows, MODIFIED)
+		printRows(report.Rows, MISSING)
 	}
 
-	for _, row := range report.Rows {
-		if row.Status == MODIFIED {
-			printRow(row)
-		}
-	}
+	printRows(report.Rows, UNTAGGED)
+}
 
-	for _, row := range report.Rows {
-		if row.Status == MISSING {
-			printRow(row)
-		}
-	}
-
-	for _, row := range report.Rows {
-		if row.Status == UNTAGGED {
+func printRows(rows []Row, status Status) {
+	for _, row := range rows {
+		if row.Status == status {
 			printRow(row)
 		}
 	}