Fix three critical UX issues in opal-task
Issue 1: Fix recurrence calculation for overdue tasks - Use completion date (End) as base for next instance, not original due date - If task due Monday completed Wednesday, next is Wednesday+7d not Monday+7d - Fallback to Due date if End is not set - Update test to verify new behavior Issue 2: Fix description parsing to work without quotes - Add parseAddArgs() to extract description from non-modifier words - Description = all words that don't start with +, -, or contain : - Enables: opal add buy groceries +shop carrots → 'buy groceries carrots' - Validate description is required (error if only modifiers) - Validate recurring tasks require due date Issue 3: Implement flexible command syntax - Add preprocessArgs() to parse arguments before Cobra routing - Detect command position and split filters (left) from modifiers (right) - Rewrite os.Args so Cobra routes correctly - Enable both 'opal 2 done' and 'opal done 2' syntax - Commands without modifiers accept filters on either side - Commands with modifiers enforce [filters] command [modifiers] - Add confirmation for modify without filters (modifies all tasks) All commands updated to use preprocessed ParsedArgs from context. All tests passing (33 tests).
This commit is contained in:
+47
-9
@@ -15,12 +15,15 @@ var addCmd = &cobra.Command{
|
||||
Long: `Add a new task with optional modifiers.
|
||||
|
||||
Examples:
|
||||
opal add "Buy groceries"
|
||||
opal add "Review PR" priority:H project:backend
|
||||
opal add "Team meeting" due:mon recur:1w +meetings`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
opal add buy groceries # No quotes needed!
|
||||
opal add review PR priority:H project:backend
|
||||
opal add buy groceries +shop carrots # Tag can be anywhere
|
||||
opal add team meeting due:mon recur:1w +meetings`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if err := addTask(args); err != nil {
|
||||
parsed := getParsedArgs(cmd)
|
||||
// For add, combine filters and modifiers (all are args to parse)
|
||||
allArgs := append(parsed.Filters, parsed.Modifiers...)
|
||||
if err := addTask(allArgs); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -28,13 +31,16 @@ Examples:
|
||||
}
|
||||
|
||||
func addTask(args []string) error {
|
||||
// First arg is description, rest are modifiers
|
||||
description := args[0]
|
||||
modifierArgs := args[1:]
|
||||
// Parse description and modifiers from args
|
||||
// Description = all words that are NOT filters/modifiers
|
||||
// Filters/Modifiers = words with +, -, or containing :
|
||||
description, modifierArgs, err := parseAddArgs(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Parse modifiers
|
||||
var mod *engine.Modifier
|
||||
var err error
|
||||
|
||||
if len(modifierArgs) > 0 {
|
||||
mod, err = engine.ParseModifier(modifierArgs)
|
||||
@@ -65,6 +71,33 @@ func addTask(args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// parseAddArgs extracts description and modifiers from args
|
||||
// Description = all non-filter/modifier words joined with spaces
|
||||
// Filters/Modifiers = args with +, -, or containing :
|
||||
func parseAddArgs(args []string) (string, []string, error) {
|
||||
var descParts []string
|
||||
var modifiers []string
|
||||
|
||||
for _, arg := range args {
|
||||
isFilterOrModifier := strings.HasPrefix(arg, "+") ||
|
||||
strings.HasPrefix(arg, "-") ||
|
||||
strings.Contains(arg, ":")
|
||||
|
||||
if isFilterOrModifier {
|
||||
modifiers = append(modifiers, arg)
|
||||
} else {
|
||||
descParts = append(descParts, arg)
|
||||
}
|
||||
}
|
||||
|
||||
if len(descParts) == 0 {
|
||||
return "", nil, fmt.Errorf("description is required")
|
||||
}
|
||||
|
||||
description := strings.Join(descParts, " ")
|
||||
return description, modifiers, nil
|
||||
}
|
||||
|
||||
func addRecurringTask(description string, mod *engine.Modifier) error {
|
||||
// Extract recurrence pattern
|
||||
recurPattern := mod.SetAttributes["recur"]
|
||||
@@ -72,6 +105,11 @@ func addRecurringTask(description string, mod *engine.Modifier) error {
|
||||
return fmt.Errorf("no recurrence pattern specified")
|
||||
}
|
||||
|
||||
// Validate: recurring tasks must have due date
|
||||
if mod.SetAttributes["due"] == nil {
|
||||
return fmt.Errorf("recurring tasks require a due date (use due:YYYY-MM-DD or due:monday)")
|
||||
}
|
||||
|
||||
duration, err := engine.ParseRecurrencePattern(*recurPattern)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid recurrence pattern: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user