fix: shell autocomplete bypasses preprocessing and completes attribute values

Bypass Execute() preprocessing for __complete/__completeNoDesc so Cobra's
built-in completion handles shell TAB without creating tasks. Add root
ValidArgsFunction for flexible syntax (e.g. "opal 1 de<TAB>" → delete),
attribute value completions (status:pending, priority:H, date synonyms),
and NoSpace directive on key: completions to avoid trailing space.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-25 22:05:15 +01:00
parent 6c28e4d24a
commit 08123aa3c5
2 changed files with 91 additions and 3 deletions
+7 -1
View File
@@ -54,8 +54,9 @@ var commandsWithModifiers = map[string]bool{
var rootCmd = &cobra.Command{
Use: "opal [filter] [command|report] [modifiers]",
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.`,
Args: cobra.ArbitraryArgs,
Run: func(cmd *cobra.Command, args []string) {
// Default behavior: run configured default report (defaults to "list")
parsed := getParsedArgs(cmd)
@@ -87,6 +88,11 @@ func Execute() error {
if firstArg == "-h" || firstArg == "--help" || firstArg == "help" {
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)