7aaaa86a0a
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>
64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.jnss.me/joakim/opal/internal/engine"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var stopCmd = &cobra.Command{
|
|
Use: "stop [filter...]",
|
|
Short: "Stop a task (clear start time)",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
parsed := getParsedArgs(cmd)
|
|
if err := stopTasks(parsed.Filters); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
},
|
|
}
|
|
|
|
func stopTasks(args []string) error {
|
|
filter, err := engine.ParseFilter(args)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
ws, _ := engine.LoadWorkingSet()
|
|
var tasks []*engine.Task
|
|
|
|
if len(filter.IDs) > 0 && ws != nil {
|
|
for _, id := range filter.IDs {
|
|
task, err := ws.GetTaskByDisplayID(id)
|
|
if err == nil {
|
|
tasks = append(tasks, task)
|
|
}
|
|
}
|
|
} else {
|
|
tasks, err = engine.GetTasks(filter)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if len(tasks) == 0 {
|
|
return fmt.Errorf("no tasks matched filter")
|
|
}
|
|
|
|
if dryRunFlag {
|
|
fmt.Print(engine.FormatTaskConfirmList("stop", tasks, ws))
|
|
fmt.Println("Dry run — no changes made.")
|
|
return nil
|
|
}
|
|
|
|
for _, task := range tasks {
|
|
task.StopTask()
|
|
engine.RecordUndo("stop", task.UUID)
|
|
fmt.Printf("Stopped task: %s\n", task.Description)
|
|
}
|
|
|
|
return nil
|
|
}
|