|
@@ -67,6 +67,8 @@ type TaskShelf interface {
|
|
|
GetAll() []Task
|
|
|
// Render a task to a task template
|
|
|
RenderTask(task Task) string
|
|
|
+ // Clean the shelf of all completed tasks
|
|
|
+ Clean() int
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -193,6 +195,22 @@ func (f *FilesystemShelf) DeleteTask(id int) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+// Clean the filesystem shelf of all completed tasks
|
|
|
+func (f *FilesystemShelf) Clean() int {
|
|
|
+ replTasks := []Task{}
|
|
|
+ var cleaned int
|
|
|
+ cleaned = 0
|
|
|
+ for i := range f.Tasks {
|
|
|
+ if f.Tasks[i].Done {
|
|
|
+ cleaned += 1
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ replTasks = append(replTasks, f.Tasks[i])
|
|
|
+ }
|
|
|
+ os.WriteFile(f.SaveLocation, marshalTaskToShelf(replTasks, f.Template), os.ModePerm)
|
|
|
+ return cleaned
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
Mark task as done and write the shelf to disk. since the Tasks within FilesystemShelf are
|
|
|
values and not pointers, we need to copy the entirety of the shelf over to a new set
|