make sure Projects and Contexts are sorted

This commit is contained in:
jamesclonk@jamesclonk.ch 2014-01-04 16:32:40 +01:00
parent e8603bbc85
commit 96cc4ce27c
2 changed files with 3 additions and 1 deletions

View File

@ -53,12 +53,14 @@ func (task Task) String() string {
text += task.Todo text += task.Todo
if len(task.Contexts) > 0 { if len(task.Contexts) > 0 {
sort.Strings(task.Contexts)
for _, context := range task.Contexts { for _, context := range task.Contexts {
text += fmt.Sprintf(" @%s", context) text += fmt.Sprintf(" @%s", context)
} }
} }
if len(task.Projects) > 0 { if len(task.Projects) > 0 {
sort.Strings(task.Projects)
for _, project := range task.Projects { for _, project := range task.Projects {
text += fmt.Sprintf(" +%s", project) text += fmt.Sprintf(" +%s", project)
} }

View File

@ -188,7 +188,7 @@ func (tasklist *TaskList) LoadFromFilename(filename string) error {
// WriteToFilename writes a TaskList to the specified file (most likely called "todo.txt"). // WriteToFilename writes a TaskList to the specified file (most likely called "todo.txt").
func (tasklist *TaskList) WriteToFilename(filename string) error { func (tasklist *TaskList) WriteToFilename(filename string) error {
return ioutil.WriteFile(filename, []byte(tasklist.String()), 0644) return ioutil.WriteFile(filename, []byte(tasklist.String()), 0640)
} }
// LoadFromFile loads and returns a TaskList from *os.File. // LoadFromFile loads and returns a TaskList from *os.File.