Implement opal-task Phases 6-8: Complete CLI Implementation

Phase 6: Display and Basic Commands
- Add display.go with colored formatting for tasks, projects, tags
- Implement cmd/root.go with Cobra command structure
- Implement cmd/list.go for listing and filtering tasks
- Implement cmd/add.go with support for regular and recurring tasks
- Implement cmd/done.go with bulk completion and confirmation

Phase 7: Advanced Commands
- Implement cmd/modify.go for updating task attributes
- Implement cmd/delete.go with soft delete confirmation
- Implement cmd/start.go and cmd/stop.go for task timing
- Implement cmd/count.go for counting filtered tasks
- Implement cmd/projects.go and cmd/tags.go for aggregation

Phase 8: Integration and Polish
- Update main.go to use CLI commands
- Add colored output with fatih/color
- Format task lists with proper alignment
- Highlight overdue tasks in red, upcoming in yellow
- Test end-to-end workflow: add, list, done, recurring tasks
- Verify recurrence spawning works correctly

All CLI commands functional and tested!
This commit is contained in:
2026-01-04 18:17:04 +01:00
parent cb4b7ac14b
commit 6e6c3dbea4
13 changed files with 919 additions and 15 deletions
+89 -1
View File
@@ -1,3 +1,91 @@
package cmd
// TODO: Implement done command
import (
"fmt"
"os"
"git.jnss.me/joakim/opal/internal/engine"
"github.com/spf13/cobra"
)
var doneCmd = &cobra.Command{
Use: "done [filter...]",
Short: "Mark tasks as completed",
Long: `Mark one or more tasks as completed.
Examples:
opal 1 done # Complete task with display ID 1
opal +urgent done # Complete all urgent tasks
opal project:backend done`,
Run: func(cmd *cobra.Command, args []string) {
if err := completeTasks(args); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
},
}
func completeTasks(args []string) error {
// Parse filter
filter, err := engine.ParseFilter(args)
if err != nil {
return fmt.Errorf("failed to parse filter: %w", err)
}
// Load working set to resolve IDs
ws, err := engine.LoadWorkingSet()
if err != nil {
return fmt.Errorf("failed to load working set: %w", err)
}
// Get matching tasks
var tasks []*engine.Task
if len(filter.IDs) > 0 {
// Resolve display IDs
for _, id := range filter.IDs {
task, err := ws.GetTaskByDisplayID(id)
if err != nil {
return err
}
tasks = append(tasks, task)
}
} else {
// Use filter to get tasks
matched, err := engine.GetTasks(filter)
if err != nil {
return fmt.Errorf("failed to get tasks: %w", err)
}
tasks = matched
}
if len(tasks) == 0 {
fmt.Println("No tasks matched.")
return nil
}
// Confirm if multiple tasks
if len(tasks) > 1 {
fmt.Printf("About to complete %d tasks. Proceed? (y/N): ", len(tasks))
var confirm string
fmt.Scanln(&confirm)
if confirm != "y" && confirm != "Y" {
fmt.Println("Cancelled.")
return nil
}
}
// Complete tasks
completed := 0
for _, task := range tasks {
if err := task.Complete(); err != nil {
fmt.Fprintf(os.Stderr, "Warning: failed to complete task %s: %v\n", task.UUID, err)
} else {
completed++
}
}
fmt.Printf("Completed %d task(s).\n", completed)
return nil
}