From c2c2ad14ad2279995866f36c3642f8a25a98f5dd Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Wed, 20 Feb 2019 07:53:11 -0600 Subject: [PATCH] Add Archive (quick append to the given file) --- todotxt.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/todotxt.go b/todotxt.go index 293e14b..bc199c8 100644 --- a/todotxt.go +++ b/todotxt.go @@ -109,6 +109,19 @@ func (tasklist *TaskList) RemoveTask(task Task) error { return nil } +func (tasklist *TaskList) ArchiveTaskToFile(task Task, filename string) error { + if err := tasklist.RemoveTask(task); err != nil { + return err + } + f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0600) + if err != nil { + return err + } + defer f.Close() + _, err = f.WriteString("\n" + task.String()) + return err +} + // Filter filters the current TaskList for the given predicate (a function that takes a task as input and returns a bool), // and returns a new TaskList. The original TaskList is not modified. func (tasklist *TaskList) Filter(predicate func(Task) bool) *TaskList {