Path cleanup.

This commit is contained in:
2013-08-13 20:54:10 -07:00
parent 4c43b679a1
commit 7a90676cda
6 changed files with 0 additions and 0 deletions

48
notmuch/notmuch.go Normal file
View File

@@ -0,0 +1,48 @@
package notmuch
import (
"log"
"strconv"
"strings"
"os/exec"
)
const (
notmuchCmd = "notmuch"
unreadThreadCountArgs = "count --output=threads tag:unread"
unreadMessageCountArgs = "count --output=messages tag:unread"
)
type Notmuch struct {
}
func NewNotmuch(_ string) *Notmuch {
return &Notmuch{}
}
func notmuchMust(options []string) string {
cmd := exec.Command(notmuchCmd, options...)
b, err := cmd.Output()
if err != nil {
log.Fatalf("Failed to read from process %v: %s\n", cmd, err)
}
return string(b)
}
func intFromCommand(options string) int {
output := notmuchMust(strings.Fields(options))
cnt, err := strconv.Atoi(strings.TrimSpace(output))
if err != nil {
log.Fatalf("Failed to parse int from %q: %s\n", output, err)
}
return cnt
}
func (nm *Notmuch) UnreadMessageCount() int {
return intFromCommand(unreadMessageCountArgs)
}
func (nm *Notmuch) UnreadThreadCount() int {
return intFromCommand(unreadThreadCountArgs)
}

21
notmuch/notmuch_test.go Normal file
View File

@@ -0,0 +1,21 @@
package notmuch
import (
"testing"
)
func TestUnreadMessageCount(t *testing.T) {
nm := NewNotmuch("")
count := nm.UnreadMessageCount()
if count <= 0 {
t.Errorf("Count wasn't enough, expected > 0, got %d\n", count)
}
}
func TestUnreadThreadCount(t *testing.T) {
nm := NewNotmuch("")
count := nm.UnreadThreadCount()
if count <= 0 {
t.Errorf("Count wasn't enough, expected > 0, got %d\n", count)
}
}