79eb3bb62a
- Add 'opal info' command to display detailed task information - Shows all task attributes including UUID, timestamps, and metadata - Supports flexible syntax (opal info 2 or opal 2 info) - Displays recurrence information and parent UUID for recurring tasks - Add 'opal edit' command to edit tasks in $EDITOR - Opens task in text editor with human-readable format - Supports all editable fields with smart date formatting - Special handling for recurring tasks (updates parent template) - Status changes trigger appropriate methods (Complete/Delete) - Auto-saves changes on editor exit without confirmation - Clear validation and error messages - Register new commands in root command dispatcher
81 lines
1.9 KiB
Go
81 lines
1.9 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.jnss.me/joakim/opal/internal/engine"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var infoCmd = &cobra.Command{
|
|
Use: "info [filter...]",
|
|
Short: "Show detailed information about a task",
|
|
Long: `Display all details about a specific task.
|
|
|
|
Examples:
|
|
opal info 2 # Show details for task with display ID 2
|
|
opal 2 info # Flexible syntax (same as above)
|
|
opal info +urgent # Show details if only one task matches`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
parsed := getParsedArgs(cmd)
|
|
if err := showTaskInfo(parsed.Filters); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
},
|
|
}
|
|
|
|
func showTaskInfo(args []string) error {
|
|
// Validate we have a filter
|
|
if len(args) == 0 {
|
|
return fmt.Errorf("no task specified for info command")
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
|
|
// Resolve task
|
|
var task *engine.Task
|
|
|
|
if len(filter.IDs) > 0 {
|
|
// Resolve display ID (should be exactly one)
|
|
if len(filter.IDs) != 1 {
|
|
return fmt.Errorf("info requires exactly one task (specified %d IDs)", len(filter.IDs))
|
|
}
|
|
task, err = ws.GetTaskByDisplayID(filter.IDs[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
} else {
|
|
// Use filter to get tasks
|
|
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 task found matching filter")
|
|
}
|
|
if len(tasks) > 1 {
|
|
return fmt.Errorf("info requires exactly one task (filter matched %d tasks)", len(tasks))
|
|
}
|
|
|
|
task = tasks[0]
|
|
}
|
|
|
|
// Display detailed info
|
|
fmt.Println(engine.FormatTaskDetail(task))
|
|
|
|
return nil
|
|
}
|