Browse Source

minor tweaks

aeth 1 month ago
parent
commit
8fbf4eb5ed
2 changed files with 15 additions and 8 deletions
  1. 8 2
      cmd/main.go
  2. 7 6
      pkg/savestate.go

+ 8 - 2
cmd/main.go

@@ -6,6 +6,7 @@ import (
 	"log"
 	"os"
 	"strconv"
+	"strings"
 
 	itashi "git.aetherial.dev/aeth/itashi/pkg"
 	tea "github.com/charmbracelet/bubbletea"
@@ -36,12 +37,17 @@ func main() {
 			shelf.DeleteTask(id)
 			os.Exit(0)
 		case DONE_TASK:
+			var taskName string
 			id, err := strconv.Atoi(args[2])
 			if err != nil {
 				log.Fatal("ID passed was not a valid integer: ", err)
 			}
-			shelf.MarkDone(id)
-			fmt.Print("よくできた! Good job!\n")
+			taskName = shelf.MarkDone(id)
+			if taskName == "" {
+				fmt.Printf("No task was indexed with ID: %v\n", id)
+				os.Exit(0)
+			}
+			fmt.Printf("よくできた! Good job! Task '%s' was marked complete!\n", strings.TrimSuffix(taskName, "\n"))
 			os.Exit(0)
 		case TIDY_TASK:
 			fmt.Printf("Shelf tidied, removed %v completed tasks.\n", shelf.Clean())

+ 7 - 6
pkg/savestate.go

@@ -58,7 +58,7 @@ type TaskShelf interface {
 	// delete an existing task from the shelf
 	DeleteTask(id int)
 	// Mark a task as complete
-	MarkDone(id int)
+	MarkDone(id int) string
 	// hopefully you dont need to call this! ;)
 	ResetDone(id int)
 	// Add a task to the shelf
@@ -219,25 +219,26 @@ and write it, as opposed to just modifying the pointer and then writing.
 	    :param id: the ID of the task to mark as done
 		:returns: Nothing
 */
-func (f *FilesystemShelf) MarkDone(id int) {
+func (f *FilesystemShelf) MarkDone(id int) string {
 	replTasks := []Task{}
+	var taskName string
 	for i := range f.Tasks {
 		if f.Tasks[i].Id == id {
-			doneTask := Task{
+			replTasks = append(replTasks, Task{
 				Id:       f.Tasks[i].Id,
 				Title:    f.Tasks[i].Title,
 				Desc:     f.Tasks[i].Desc,
 				Due:      f.Tasks[i].Due,
 				Done:     true,
 				Priority: f.Tasks[i].Priority,
-			}
-			replTasks = append(replTasks, doneTask)
+			})
+			taskName = f.Tasks[i].Title
 			continue
 		}
 		replTasks = append(replTasks, f.Tasks[i])
 	}
 	os.WriteFile(f.SaveLocation, marshalTaskToShelf(replTasks, f.Template), os.ModePerm)
-
+	return taskName
 }
 
 func (f *FilesystemShelf) ResetDone(id int) {}