Files
gems/opal-task/cmd/stop.go
T
joakim f57baee6bc fix: IMP-4/5/6 — parser allowlist, delete ID resolution, consistent errors
IMP-5: Replace strings.Contains(arg, ":") heuristic with an allowlist
of recognized attribute keys (ValidAttributeKeys). Colons in task
descriptions (URLs, "Meeting: topic") are no longer misinterpreted as
modifiers. Canonical key sets live in engine/keys.go and are shared
across parseAddArgs, ParseFilter, and ParseModifier. ParseModifier now
errors on unknown keys.

IMP-4: delete command now loads the working set and resolves display IDs
via GetTaskByDisplayID, matching the pattern used by done/modify.

IMP-6: All action commands (done, delete, modify, start, stop) now
return an error on no-match (stderr, exit 1). Previously done/delete
printed to stdout and exited 0; start/stop had no check at all.

Also adds requirements and design docs for the CLI UX improvements.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 13:37:33 +01:00

57 lines
1.0 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")
}
for _, task := range tasks {
task.StopTask()
fmt.Printf("Stopped task: %s\n", task.Description)
}
return nil
}