Compare commits
7 Commits
9973631df0
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d57aed8ce | |||
| 393b7a144a | |||
| 201f32d095 | |||
| e86d063912 | |||
| 10421b0ec6 | |||
| 08123aa3c5 | |||
| 6c28e4d24a |
+1
-1
@@ -1 +1 @@
|
|||||||
0.1.0
|
0.2.0
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.jnss.me/joakim/opal/internal/engine"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var olderFlag string
|
||||||
|
|
||||||
|
var cleanCmd = &cobra.Command{
|
||||||
|
Use: "clean",
|
||||||
|
Short: "Purge soft-deleted tasks from the database",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if err := cleanTasks(); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cleanCmd.Flags().StringVar(&olderFlag, "older", "", "Only purge tasks deleted longer than this duration ago (e.g. 30d, 1w)")
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanTasks() error {
|
||||||
|
var olderThan *time.Duration
|
||||||
|
if olderFlag != "" {
|
||||||
|
d, err := engine.ParseRecurrencePattern(olderFlag)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid duration %q: %w", olderFlag, err)
|
||||||
|
}
|
||||||
|
olderThan = &d
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks, err := engine.GetDeletedTasks(olderThan)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(tasks) == 0 {
|
||||||
|
fmt.Println("No deleted tasks to purge.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if dryRunFlag {
|
||||||
|
fmt.Printf("Would permanently remove %d deleted task(s).\n", len(tasks))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(tasks) > 1 {
|
||||||
|
fmt.Printf("Permanently remove %d deleted task(s)? This cannot be undone. (y/N): ", len(tasks))
|
||||||
|
var confirm string
|
||||||
|
fmt.Scanln(&confirm)
|
||||||
|
if confirm != "y" && confirm != "Y" {
|
||||||
|
fmt.Println("Cancelled.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, task := range tasks {
|
||||||
|
if err := task.Delete(true); err != nil {
|
||||||
|
return fmt.Errorf("failed to purge task %s: %w", task.UUID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Purged %d deleted task(s).\n", len(tasks))
|
||||||
|
|
||||||
|
if err := engine.CleanupChangeLog(); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Warning: failed to clean up change log: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -2,14 +2,37 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.jnss.me/joakim/opal/internal/engine"
|
"git.jnss.me/joakim/opal/internal/engine"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// taskFilterCompletion provides dynamic completions for task filter arguments.
|
// taskFilterCompletion provides dynamic completions for task filter arguments.
|
||||||
// Suggests +tag and project:name completions from the database.
|
// Suggests +tag, project:name, and attribute value completions from the database.
|
||||||
func taskFilterCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
func taskFilterCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
// If typing a key:value, complete the value part
|
||||||
|
if idx := strings.IndexByte(toComplete, ':'); idx >= 0 {
|
||||||
|
key := toComplete[:idx]
|
||||||
|
if engine.ValidAttributeKeys[key] {
|
||||||
|
return attributeValueCompletions(key, toComplete), cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If toComplete is a prefix of an attribute key, return only key:
|
||||||
|
// completions with NoSpace so the cursor stays after the colon.
|
||||||
|
if toComplete != "" && !strings.HasPrefix(toComplete, "+") && !strings.HasPrefix(toComplete, "-") {
|
||||||
|
var keyCompletions []string
|
||||||
|
for key := range engine.ValidAttributeKeys {
|
||||||
|
if strings.HasPrefix(key, toComplete) {
|
||||||
|
keyCompletions = append(keyCompletions, fmt.Sprintf("%s:", key))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(keyCompletions) > 0 {
|
||||||
|
return keyCompletions, cobra.ShellCompDirectiveNoFileComp | cobra.ShellCompDirectiveNoSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var completions []string
|
var completions []string
|
||||||
|
|
||||||
tags, err := engine.GetAllTags()
|
tags, err := engine.GetAllTags()
|
||||||
@@ -31,10 +54,69 @@ func taskFilterCompletion(cmd *cobra.Command, args []string, toComplete string)
|
|||||||
completions = append(completions, fmt.Sprintf("%s:", key))
|
completions = append(completions, fmt.Sprintf("%s:", key))
|
||||||
}
|
}
|
||||||
|
|
||||||
return completions, cobra.ShellCompDirectiveNoFileComp
|
return completions, cobra.ShellCompDirectiveNoFileComp | cobra.ShellCompDirectiveNoSpace
|
||||||
|
}
|
||||||
|
|
||||||
|
// attributeValueCompletions returns key:value completions for a known attribute key.
|
||||||
|
// Cobra filters by prefix automatically, so we return all values prefixed with "key:".
|
||||||
|
func attributeValueCompletions(key, toComplete string) []string {
|
||||||
|
var values []string
|
||||||
|
|
||||||
|
switch key {
|
||||||
|
case "status":
|
||||||
|
values = []string{"pending", "completed", "deleted", "recurring"}
|
||||||
|
case "priority":
|
||||||
|
values = []string{"H", "M", "L"}
|
||||||
|
case "project":
|
||||||
|
projects, err := engine.GetAllProjects()
|
||||||
|
if err == nil {
|
||||||
|
values = projects
|
||||||
|
}
|
||||||
|
case "due", "wait", "scheduled", "until":
|
||||||
|
values = []string{
|
||||||
|
"today", "tomorrow", "yesterday", "now",
|
||||||
|
"eod", "sow", "eow", "som", "eom",
|
||||||
|
"mon", "tue", "wed", "thu", "fri", "sat", "sun",
|
||||||
|
}
|
||||||
|
case "recur":
|
||||||
|
values = []string{"daily", "weekly", "monthly", "yearly", "1d", "1w", "2w", "1m", "1y"}
|
||||||
|
}
|
||||||
|
|
||||||
|
completions := make([]string, 0, len(values))
|
||||||
|
for _, v := range values {
|
||||||
|
completions = append(completions, fmt.Sprintf("%s:%s", key, v))
|
||||||
|
}
|
||||||
|
return completions
|
||||||
|
}
|
||||||
|
|
||||||
|
// rootValidArgsFunction provides completions for root-level arguments,
|
||||||
|
// enabling flexible syntax like "opal 1 de<TAB>" to complete to "delete".
|
||||||
|
func rootValidArgsFunction(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
// Delegate to taskFilterCompletion first — if toComplete is a partial
|
||||||
|
// attribute key, it returns early with NoSpace and we should honour that.
|
||||||
|
filterCompletions, directive := taskFilterCompletion(cmd, args, toComplete)
|
||||||
|
|
||||||
|
var completions []string
|
||||||
|
|
||||||
|
// Suggest command names
|
||||||
|
for _, name := range commandNames {
|
||||||
|
completions = append(completions, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Suggest report names
|
||||||
|
for _, name := range reportNames {
|
||||||
|
completions = append(completions, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
completions = append(completions, filterCompletions...)
|
||||||
|
|
||||||
|
return completions, directive
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
// Root command completions for flexible syntax (e.g., "opal 1 de<TAB>")
|
||||||
|
rootCmd.ValidArgsFunction = rootValidArgsFunction
|
||||||
|
|
||||||
// Register dynamic completions for commands that accept filters
|
// Register dynamic completions for commands that accept filters
|
||||||
addCmd.ValidArgsFunction = taskFilterCompletion
|
addCmd.ValidArgsFunction = taskFilterCompletion
|
||||||
doneCmd.ValidArgsFunction = taskFilterCompletion
|
doneCmd.ValidArgsFunction = taskFilterCompletion
|
||||||
|
|||||||
+31
-10
@@ -8,19 +8,25 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var hardDeleteFlag bool
|
||||||
|
|
||||||
var deleteCmd = &cobra.Command{
|
var deleteCmd = &cobra.Command{
|
||||||
Use: "delete [filter...]",
|
Use: "delete [filter...]",
|
||||||
Short: "Delete tasks",
|
Short: "Delete tasks",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
parsed := getParsedArgs(cmd)
|
parsed := getParsedArgs(cmd)
|
||||||
if err := deleteTasks(parsed.Filters); err != nil {
|
if err := deleteTasks(parsed.Filters, hardDeleteFlag); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteTasks(args []string) error {
|
func init() {
|
||||||
|
deleteCmd.Flags().BoolVar(&hardDeleteFlag, "hard", false, "Permanently remove task from database")
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteTasks(args []string, hard bool) error {
|
||||||
filter, err := engine.ParseFilter(args)
|
filter, err := engine.ParseFilter(args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -53,15 +59,24 @@ func deleteTasks(args []string) error {
|
|||||||
return fmt.Errorf("no tasks matched filter")
|
return fmt.Errorf("no tasks matched filter")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
action := "delete"
|
||||||
|
if hard {
|
||||||
|
action = "permanently delete"
|
||||||
|
}
|
||||||
|
|
||||||
if dryRunFlag {
|
if dryRunFlag {
|
||||||
fmt.Print(engine.FormatTaskConfirmList("delete", tasks, ws))
|
fmt.Print(engine.FormatTaskConfirmList(action, tasks, ws))
|
||||||
fmt.Println("Dry run — no changes made.")
|
fmt.Println("Dry run — no changes made.")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(tasks) > 1 {
|
if len(tasks) > 1 || hard {
|
||||||
fmt.Print(engine.FormatTaskConfirmList("delete", tasks, ws))
|
fmt.Print(engine.FormatTaskConfirmList(action, tasks, ws))
|
||||||
fmt.Printf("Proceed? (y/N): ")
|
if hard {
|
||||||
|
fmt.Printf("This cannot be undone. Proceed? (y/N): ")
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Proceed? (y/N): ")
|
||||||
|
}
|
||||||
var confirm string
|
var confirm string
|
||||||
fmt.Scanln(&confirm)
|
fmt.Scanln(&confirm)
|
||||||
if confirm != "y" && confirm != "Y" {
|
if confirm != "y" && confirm != "Y" {
|
||||||
@@ -71,14 +86,20 @@ func deleteTasks(args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, task := range tasks {
|
for _, task := range tasks {
|
||||||
task.Delete(false) // Soft delete
|
task.Delete(hard)
|
||||||
engine.RecordUndo("delete", task.UUID)
|
if !hard {
|
||||||
|
engine.RecordUndo("delete", task.UUID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
verb := "Deleted"
|
||||||
|
if hard {
|
||||||
|
verb = "Permanently deleted"
|
||||||
|
}
|
||||||
if len(tasks) == 1 {
|
if len(tasks) == 1 {
|
||||||
fmt.Printf("Deleted task %s\n", engine.FormatTaskSummary(tasks[0], ws))
|
fmt.Printf("%s task %s\n", verb, engine.FormatTaskSummary(tasks[0], ws))
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Deleted %d task(s).\n", len(tasks))
|
fmt.Printf("%s %d task(s).\n", verb, len(tasks))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-2
@@ -32,7 +32,7 @@ var (
|
|||||||
|
|
||||||
// Command classification
|
// Command classification
|
||||||
var commandNames = []string{
|
var commandNames = []string{
|
||||||
"add", "done", "modify", "delete",
|
"add", "done", "modify", "delete", "clean",
|
||||||
"start", "stop", "count", "projects", "tags",
|
"start", "stop", "count", "projects", "tags",
|
||||||
"info", "edit", "server", "sync", "reports", "setup",
|
"info", "edit", "server", "sync", "reports", "setup",
|
||||||
"version", "annotate", "denotate", "undo", "uncomplete", "log", "completion",
|
"version", "annotate", "denotate", "undo", "uncomplete", "log", "completion",
|
||||||
@@ -54,8 +54,9 @@ var commandsWithModifiers = map[string]bool{
|
|||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "opal [filter] [command|report] [modifiers]",
|
Use: "opal [filter] [command|report] [modifiers]",
|
||||||
Short: "Opal task manager - taskwarrior-inspired CLI task management",
|
Short: "Opal task manager - taskwarrior-inspired CLI task management",
|
||||||
Long: `Opal is a powerful command-line task manager.
|
Long: `Opal is a powerful command-line task manager.
|
||||||
It supports filtering, tags, priorities, projects, and recurring tasks.`,
|
It supports filtering, tags, priorities, projects, and recurring tasks.`,
|
||||||
|
Args: cobra.ArbitraryArgs,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
// Default behavior: run configured default report (defaults to "list")
|
// Default behavior: run configured default report (defaults to "list")
|
||||||
parsed := getParsedArgs(cmd)
|
parsed := getParsedArgs(cmd)
|
||||||
@@ -87,6 +88,11 @@ func Execute() error {
|
|||||||
if firstArg == "-h" || firstArg == "--help" || firstArg == "help" {
|
if firstArg == "-h" || firstArg == "--help" || firstArg == "help" {
|
||||||
return rootCmd.Execute()
|
return rootCmd.Execute()
|
||||||
}
|
}
|
||||||
|
// Let Cobra's built-in completion machinery handle shell completions
|
||||||
|
// directly, bypassing preprocessing that would create tasks.
|
||||||
|
if firstArg == "__complete" || firstArg == "__completeNoDesc" {
|
||||||
|
return rootCmd.Execute()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preprocess arguments (read-only scan — os.Args is never mutated)
|
// Preprocess arguments (read-only scan — os.Args is never mutated)
|
||||||
@@ -278,6 +284,7 @@ func init() {
|
|||||||
undoCmd.GroupID = "task"
|
undoCmd.GroupID = "task"
|
||||||
uncompleteCmd.GroupID = "task"
|
uncompleteCmd.GroupID = "task"
|
||||||
logCmd.GroupID = "task"
|
logCmd.GroupID = "task"
|
||||||
|
cleanCmd.GroupID = "task"
|
||||||
|
|
||||||
rootCmd.AddCommand(addCmd)
|
rootCmd.AddCommand(addCmd)
|
||||||
rootCmd.AddCommand(doneCmd)
|
rootCmd.AddCommand(doneCmd)
|
||||||
@@ -292,6 +299,7 @@ func init() {
|
|||||||
rootCmd.AddCommand(undoCmd)
|
rootCmd.AddCommand(undoCmd)
|
||||||
rootCmd.AddCommand(uncompleteCmd)
|
rootCmd.AddCommand(uncompleteCmd)
|
||||||
rootCmd.AddCommand(logCmd)
|
rootCmd.AddCommand(logCmd)
|
||||||
|
rootCmd.AddCommand(cleanCmd)
|
||||||
|
|
||||||
// Other commands
|
// Other commands
|
||||||
countCmd.GroupID = "other"
|
countCmd.GroupID = "other"
|
||||||
|
|||||||
@@ -130,35 +130,35 @@ func CreateTask(w http.ResponseWriter, r *http.Request) {
|
|||||||
mod.AddTags = req.Tags
|
mod.AddTags = req.Tags
|
||||||
|
|
||||||
if req.Project != nil {
|
if req.Project != nil {
|
||||||
mod.SetAttributes["project"] = req.Project
|
mod.Set("project", req.Project)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Priority != nil {
|
if req.Priority != nil {
|
||||||
mod.SetAttributes["priority"] = req.Priority
|
mod.Set("priority", req.Priority)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Due != nil {
|
if req.Due != nil {
|
||||||
dueStr := fmt.Sprintf("%d", *req.Due)
|
dueStr := fmt.Sprintf("%d", *req.Due)
|
||||||
mod.SetAttributes["due"] = &dueStr
|
mod.Set("due", &dueStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Scheduled != nil {
|
if req.Scheduled != nil {
|
||||||
scheduledStr := fmt.Sprintf("%d", *req.Scheduled)
|
scheduledStr := fmt.Sprintf("%d", *req.Scheduled)
|
||||||
mod.SetAttributes["scheduled"] = &scheduledStr
|
mod.Set("scheduled", &scheduledStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Wait != nil {
|
if req.Wait != nil {
|
||||||
waitStr := fmt.Sprintf("%d", *req.Wait)
|
waitStr := fmt.Sprintf("%d", *req.Wait)
|
||||||
mod.SetAttributes["wait"] = &waitStr
|
mod.Set("wait", &waitStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Until != nil {
|
if req.Until != nil {
|
||||||
untilStr := fmt.Sprintf("%d", *req.Until)
|
untilStr := fmt.Sprintf("%d", *req.Until)
|
||||||
mod.SetAttributes["until"] = &untilStr
|
mod.Set("until", &untilStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Recurrence != nil {
|
if req.Recurrence != nil {
|
||||||
mod.SetAttributes["recurrence"] = req.Recurrence
|
mod.Set("recur", req.Recurrence)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create task
|
// Create task
|
||||||
@@ -232,39 +232,39 @@ func UpdateTask(w http.ResponseWriter, r *http.Request) {
|
|||||||
mod := engine.NewModifier()
|
mod := engine.NewModifier()
|
||||||
|
|
||||||
if req.Description != nil {
|
if req.Description != nil {
|
||||||
mod.SetAttributes["description"] = req.Description
|
mod.Set("description", req.Description)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Status != nil {
|
if req.Status != nil {
|
||||||
mod.SetAttributes["status"] = req.Status
|
mod.Set("status", req.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Priority != nil {
|
if req.Priority != nil {
|
||||||
mod.SetAttributes["priority"] = req.Priority
|
mod.Set("priority", req.Priority)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Project != nil {
|
if req.Project != nil {
|
||||||
mod.SetAttributes["project"] = req.Project
|
mod.Set("project", req.Project)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Due != nil {
|
if req.Due != nil {
|
||||||
dueStr := fmt.Sprintf("%d", *req.Due)
|
dueStr := fmt.Sprintf("%d", *req.Due)
|
||||||
mod.SetAttributes["due"] = &dueStr
|
mod.Set("due", &dueStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Scheduled != nil {
|
if req.Scheduled != nil {
|
||||||
scheduledStr := fmt.Sprintf("%d", *req.Scheduled)
|
scheduledStr := fmt.Sprintf("%d", *req.Scheduled)
|
||||||
mod.SetAttributes["scheduled"] = &scheduledStr
|
mod.Set("scheduled", &scheduledStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Wait != nil {
|
if req.Wait != nil {
|
||||||
waitStr := fmt.Sprintf("%d", *req.Wait)
|
waitStr := fmt.Sprintf("%d", *req.Wait)
|
||||||
mod.SetAttributes["wait"] = &waitStr
|
mod.Set("wait", &waitStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Until != nil {
|
if req.Until != nil {
|
||||||
untilStr := fmt.Sprintf("%d", *req.Until)
|
untilStr := fmt.Sprintf("%d", *req.Until)
|
||||||
mod.SetAttributes["until"] = &untilStr
|
mod.Set("until", &untilStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Start != nil {
|
if req.Start != nil {
|
||||||
@@ -273,7 +273,7 @@ func UpdateTask(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if req.Recurrence != nil {
|
if req.Recurrence != nil {
|
||||||
mod.SetAttributes["recurrence"] = req.Recurrence
|
mod.Set("recur", req.Recurrence)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply modifier
|
// Apply modifier
|
||||||
|
|||||||
@@ -4,14 +4,15 @@ package engine
|
|||||||
// Used by parseAddArgs (cmd/add.go), ParseFilter, and ParseModifier
|
// Used by parseAddArgs (cmd/add.go), ParseFilter, and ParseModifier
|
||||||
// to distinguish modifiers from description text.
|
// to distinguish modifiers from description text.
|
||||||
var ValidAttributeKeys = map[string]bool{
|
var ValidAttributeKeys = map[string]bool{
|
||||||
"due": true,
|
"description": true,
|
||||||
"priority": true,
|
"due": true,
|
||||||
"project": true,
|
"priority": true,
|
||||||
"recur": true,
|
"project": true,
|
||||||
"status": true,
|
"recur": true,
|
||||||
"wait": true,
|
"status": true,
|
||||||
"scheduled": true,
|
"wait": true,
|
||||||
"until": true,
|
"scheduled": true,
|
||||||
|
"until": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// DateKeys is the subset of ValidAttributeKeys that hold date values.
|
// DateKeys is the subset of ValidAttributeKeys that hold date values.
|
||||||
|
|||||||
@@ -23,6 +23,13 @@ func NewModifier() *Modifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set adds an attribute to the modifier, maintaining the SetAttributes and
|
||||||
|
// AttributeOrder invariant. Pass nil to clear the attribute.
|
||||||
|
func (m *Modifier) Set(key string, value *string) {
|
||||||
|
m.SetAttributes[key] = value
|
||||||
|
m.AttributeOrder = append(m.AttributeOrder, key)
|
||||||
|
}
|
||||||
|
|
||||||
// ParseModifier parses command-line args into Modifier.
|
// ParseModifier parses command-line args into Modifier.
|
||||||
// Only recognized attribute keys (ValidAttributeKeys) are accepted;
|
// Only recognized attribute keys (ValidAttributeKeys) are accepted;
|
||||||
// unrecognized key:value tokens produce an error.
|
// unrecognized key:value tokens produce an error.
|
||||||
@@ -86,6 +93,14 @@ func (m *Modifier) Apply(task *Task) error {
|
|||||||
resolvedDates["created"] = task.Created
|
resolvedDates["created"] = task.Created
|
||||||
resolvedDates["modified"] = task.Modified
|
resolvedDates["modified"] = task.Modified
|
||||||
|
|
||||||
|
// Safety net: if SetAttributes were populated without AttributeOrder,
|
||||||
|
// reconstruct order from map keys so updates aren't silently dropped.
|
||||||
|
if len(m.AttributeOrder) == 0 && len(m.SetAttributes) > 0 {
|
||||||
|
for key := range m.SetAttributes {
|
||||||
|
m.AttributeOrder = append(m.AttributeOrder, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Apply attributes in the order they were specified (important for relative references)
|
// Apply attributes in the order they were specified (important for relative references)
|
||||||
dateKeys := DateKeys
|
dateKeys := DateKeys
|
||||||
|
|
||||||
@@ -134,6 +149,14 @@ func (m *Modifier) ApplyToNew(task *Task) error {
|
|||||||
resolvedDates["created"] = task.Created
|
resolvedDates["created"] = task.Created
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Safety net: if SetAttributes were populated without AttributeOrder,
|
||||||
|
// reconstruct order from map keys so updates aren't silently dropped.
|
||||||
|
if len(m.AttributeOrder) == 0 && len(m.SetAttributes) > 0 {
|
||||||
|
for key := range m.SetAttributes {
|
||||||
|
m.AttributeOrder = append(m.AttributeOrder, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Apply attributes in the order they were specified (important for relative references)
|
// Apply attributes in the order they were specified (important for relative references)
|
||||||
dateKeys := DateKeys
|
dateKeys := DateKeys
|
||||||
|
|
||||||
@@ -156,9 +179,17 @@ func (m *Modifier) ApplyToNew(task *Task) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// applyNonDateAttribute applies a non-date attribute (priority, project, recur) to a task.
|
// applyNonDateAttribute applies a non-date attribute to a task.
|
||||||
func applyNonDateAttribute(key string, valuePtr *string, task *Task) error {
|
func applyNonDateAttribute(key string, valuePtr *string, task *Task) error {
|
||||||
switch key {
|
switch key {
|
||||||
|
case "description":
|
||||||
|
if valuePtr != nil {
|
||||||
|
task.Description = *valuePtr
|
||||||
|
}
|
||||||
|
case "status":
|
||||||
|
if valuePtr != nil && len(*valuePtr) > 0 {
|
||||||
|
task.Status = Status((*valuePtr)[0])
|
||||||
|
}
|
||||||
case "priority":
|
case "priority":
|
||||||
if valuePtr == nil {
|
if valuePtr == nil {
|
||||||
task.Priority = PriorityDefault
|
task.Priority = PriorityDefault
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ type Report struct {
|
|||||||
DisplayFormat DisplayFormat // How to display results
|
DisplayFormat DisplayFormat // How to display results
|
||||||
SortFunc func([]*Task) []*Task
|
SortFunc func([]*Task) []*Task
|
||||||
LimitFunc func([]*Task) []*Task
|
LimitFunc func([]*Task) []*Task
|
||||||
|
ShowWaiting bool // If false (default), tasks with future wait dates are hidden
|
||||||
}
|
}
|
||||||
|
|
||||||
// AllReports returns all predefined reports
|
// AllReports returns all predefined reports
|
||||||
@@ -77,6 +78,7 @@ func AllReport() *Report {
|
|||||||
Description: "All tasks",
|
Description: "All tasks",
|
||||||
BaseFilter: filter,
|
BaseFilter: filter,
|
||||||
DisplayFormat: DisplayFormatTable,
|
DisplayFormat: DisplayFormatTable,
|
||||||
|
ShowWaiting: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,6 +275,7 @@ func WaitingReport() *Report {
|
|||||||
Description: "Hidden/waiting tasks",
|
Description: "Hidden/waiting tasks",
|
||||||
BaseFilter: filter,
|
BaseFilter: filter,
|
||||||
DisplayFormat: DisplayFormatTable,
|
DisplayFormat: DisplayFormatTable,
|
||||||
|
ShowWaiting: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,6 +325,12 @@ func (r *Report) applyPostFilters(tasks []*Task) []*Task {
|
|||||||
for _, task := range tasks {
|
for _, task := range tasks {
|
||||||
include := true
|
include := true
|
||||||
|
|
||||||
|
// By default, hide tasks with a future wait date (like taskwarrior).
|
||||||
|
// Reports that need to show waiting tasks set ShowWaiting = true.
|
||||||
|
if !r.ShowWaiting && task.Wait != nil && task.Wait.After(now) {
|
||||||
|
include = false
|
||||||
|
}
|
||||||
|
|
||||||
// Check for _started marker
|
// Check for _started marker
|
||||||
if r.BaseFilter.Attributes["_started"] == "true" {
|
if r.BaseFilter.Attributes["_started"] == "true" {
|
||||||
if task.Start == nil {
|
if task.Start == nil {
|
||||||
|
|||||||
@@ -736,6 +736,48 @@ func (t *Task) IsRecurringInstance() bool {
|
|||||||
return t.ParentUUID != nil
|
return t.ParentUUID != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDeletedTasks retrieves soft-deleted tasks, optionally filtered by age.
|
||||||
|
// If olderThan is non-nil, only returns tasks deleted more than that duration ago.
|
||||||
|
func GetDeletedTasks(olderThan *time.Duration) ([]*Task, error) {
|
||||||
|
db := GetDB()
|
||||||
|
if db == nil {
|
||||||
|
return nil, fmt.Errorf("database not initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `
|
||||||
|
SELECT id, uuid, status, description, project, priority,
|
||||||
|
created, modified, start, end, due, scheduled, wait, until_date,
|
||||||
|
recurrence_duration, parent_uuid, annotations
|
||||||
|
FROM tasks
|
||||||
|
WHERE status = ?`
|
||||||
|
args := []interface{}{byte(StatusDeleted)}
|
||||||
|
|
||||||
|
if olderThan != nil {
|
||||||
|
cutoff := timeNow().Add(-*olderThan).Unix()
|
||||||
|
query += ` AND end < ?`
|
||||||
|
args = append(args, cutoff)
|
||||||
|
}
|
||||||
|
|
||||||
|
query += ` ORDER BY end ASC`
|
||||||
|
|
||||||
|
rows, err := db.Query(query, args...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to query deleted tasks: %w", err)
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
var tasks []*Task
|
||||||
|
for rows.Next() {
|
||||||
|
task, err := scanTask(rows)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to scan task: %w", err)
|
||||||
|
}
|
||||||
|
tasks = append(tasks, task)
|
||||||
|
}
|
||||||
|
|
||||||
|
return tasks, nil
|
||||||
|
}
|
||||||
|
|
||||||
// PopulateUrgency computes and sets the Urgency field on the given tasks.
|
// PopulateUrgency computes and sets the Urgency field on the given tasks.
|
||||||
func PopulateUrgency(tasks ...*Task) {
|
func PopulateUrgency(tasks ...*Task) {
|
||||||
cfg, _ := GetConfig()
|
cfg, _ := GetConfig()
|
||||||
|
|||||||
@@ -402,6 +402,12 @@
|
|||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
{:else}
|
||||||
|
<!-- svelte-ignore a11y-click-events-have-key-events a11y-no-static-element-interactions -->
|
||||||
|
<div class="field-row editable" on:click={() => startEdit('scheduled')}>
|
||||||
|
<span class="field-label">Scheduled</span>
|
||||||
|
<span class="field-value clickable">Set...</span>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!-- Wait -->
|
<!-- Wait -->
|
||||||
@@ -425,6 +431,12 @@
|
|||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
{:else}
|
||||||
|
<!-- svelte-ignore a11y-click-events-have-key-events a11y-no-static-element-interactions -->
|
||||||
|
<div class="field-row editable" on:click={() => startEdit('wait')}>
|
||||||
|
<span class="field-label">Wait</span>
|
||||||
|
<span class="field-value clickable">Set...</span>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!-- Until -->
|
<!-- Until -->
|
||||||
@@ -448,6 +460,12 @@
|
|||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
{:else}
|
||||||
|
<!-- svelte-ignore a11y-click-events-have-key-events a11y-no-static-element-interactions -->
|
||||||
|
<div class="field-row editable" on:click={() => startEdit('until')}>
|
||||||
|
<span class="field-label">Until</span>
|
||||||
|
<span class="field-value clickable">Set...</span>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!-- Active since -->
|
<!-- Active since -->
|
||||||
|
|||||||
@@ -37,6 +37,11 @@
|
|||||||
// Subscribe to store
|
// Subscribe to store
|
||||||
const unsubscribe = tasksStore.subscribe(value => {
|
const unsubscribe = tasksStore.subscribe(value => {
|
||||||
tasks = value;
|
tasks = value;
|
||||||
|
// Keep selectedTask in sync with store changes
|
||||||
|
if (selectedTask) {
|
||||||
|
const updated = value.find(t => t.uuid === selectedTask.uuid);
|
||||||
|
if (updated) selectedTask = updated;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
@@ -197,10 +202,6 @@
|
|||||||
async function handleUpdate(uuid, updates) {
|
async function handleUpdate(uuid, updates) {
|
||||||
try {
|
try {
|
||||||
await tasksStore.updateTask(uuid, updates);
|
await tasksStore.updateTask(uuid, updates);
|
||||||
// Keep selectedTask fresh
|
|
||||||
if (selectedTask?.uuid === uuid) {
|
|
||||||
selectedTask = { ...selectedTask, ...updates };
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to update task:', error);
|
console.error('Failed to update task:', error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user