summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-29 11:40:56 -0400
committerdemo <demo@antix1>2026-05-29 11:56:15 -0400
commit32f2ce19cc5e96cf34c8be1da9308412a4010383 (patch)
tree7a613156ae31701124eead2dfa4499b1cd7a4c49
parent84be938756a0a6163ff752b1e1547631d2f7a5b3 (diff)
feat: add an "undo" command
This puts a task back in the TODO state. Some refactoring here lets us reuse the same code for handling both cmdDo and cmdUndo.
-rw-r--r--cmds.go12
-rw-r--r--main.go19
2 files changed, 29 insertions, 2 deletions
diff --git a/cmds.go b/cmds.go
index 5791546..38be692 100644
--- a/cmds.go
+++ b/cmds.go
@@ -43,7 +43,7 @@ func (ctrl controller) cmdAdd(task string) error {
})
}
-func (ctrl controller) cmdDo(taskIndex int) error {
+func (ctrl controller) toggleDo(taskIndex int, status bool) error {
return ctrl.db.Update(func(tx *bbolt.Tx) error {
taskBucket := tx.Bucket(ctrl.tasksBucketName)
ttBytes := taskBucket.Get(itob(uint64(taskIndex)))
@@ -53,7 +53,7 @@ func (ctrl controller) cmdDo(taskIndex int) error {
return fmt.Errorf("can't unmarshal: %w", err)
}
- tt.Done = true
+ tt.Done = status
buf, err := json.Marshal(tt)
if err != nil {
@@ -64,6 +64,14 @@ func (ctrl controller) cmdDo(taskIndex int) error {
})
}
+func (ctrl controller) cmdDo(taskIndex int) error {
+ return ctrl.toggleDo(taskIndex, true)
+}
+
+func (ctrl controller) cmdUndo(taskIndex int) error {
+ return ctrl.toggleDo(taskIndex, false)
+}
+
func (ctrl controller) cmdList() error {
return ctrl.db.View(func(tx *bbolt.Tx) error {
// Assume bucket exists and has keys
diff --git a/main.go b/main.go
index 85bfa26..7838fcb 100644
--- a/main.go
+++ b/main.go
@@ -82,6 +82,25 @@ func main() {
},
},
{
+ Name: "undo",
+ Aliases: []string{"u"},
+ Usage: "reset a task on the list",
+ Arguments: []cli.Argument{
+ &cli.IntArg{
+ Name: "taskIndex",
+ },
+ },
+ Action: func(ctx context.Context, cmd *cli.Command) error {
+ taskIndex := cmd.IntArg("taskIndex")
+
+ if taskIndex <= 0 {
+ return fmt.Errorf("invalid 'undo' argument: %d", taskIndex)
+ }
+
+ return ctrl.cmdUndo(taskIndex)
+ },
+ },
+ {
Name: "list",
Aliases: []string{"l"},
Usage: "list pending tasks",