feat: add annotations, undo system, and schema updates
Add annotations as JSON column on tasks table with Annotate/Denotate methods and CLI commands. Add undo system backed by change_log with lightweight undo_stack table (capped at 10 entries). All mutating CLI commands (add, done, delete, modify, start, stop) now record undo entries. Undo restores prior task state from change_log data. Schema changes (in v1 migration): - annotations TEXT column on tasks - undo_stack table - annotations field in change_log triggers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.jnss.me/joakim/opal/internal/engine"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var denotateCmd = &cobra.Command{
|
||||
Use: "denotate [filter...]",
|
||||
Short: "Remove the most recent annotation from a task",
|
||||
Long: `Remove the most recent annotation from a task.
|
||||
|
||||
Examples:
|
||||
opal 2 denotate
|
||||
opal denotate +bug`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
parsed := getParsedArgs(cmd)
|
||||
if err := denotateTask(parsed.Filters); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func denotateTask(filterArgs []string) error {
|
||||
if len(filterArgs) == 0 {
|
||||
return fmt.Errorf("no task specified")
|
||||
}
|
||||
|
||||
filter, err := engine.ParseFilter(filterArgs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse filter: %w", err)
|
||||
}
|
||||
|
||||
ws, err := engine.LoadWorkingSet()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to load working set: %w", err)
|
||||
}
|
||||
|
||||
var task *engine.Task
|
||||
|
||||
if len(filter.IDs) > 0 {
|
||||
if len(filter.IDs) != 1 {
|
||||
return fmt.Errorf("denotate requires exactly one task")
|
||||
}
|
||||
task, err = ws.GetTaskByDisplayID(filter.IDs[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
tasks, err := engine.GetTasks(filter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get tasks: %w", err)
|
||||
}
|
||||
if len(tasks) == 0 {
|
||||
return fmt.Errorf("no tasks matched filter")
|
||||
}
|
||||
if len(tasks) > 1 {
|
||||
return fmt.Errorf("denotate requires exactly one task (filter matched %d)", len(tasks))
|
||||
}
|
||||
task = tasks[0]
|
||||
}
|
||||
|
||||
removed, err := task.Denotate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Removed annotation: %s\n", removed.Text)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user