feat: add shell completions, command grouping, and dynamic completions

Add completion command for bash/zsh/fish/powershell generation. Organize
help text using Cobra command groups (Task Commands, Reports, Other).
Register dynamic ValidArgsFunction on filter-accepting commands to
suggest +tag and project:name completions from the database.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-19 13:59:21 +01:00
parent 32cc05a546
commit feb5406077
6 changed files with 139 additions and 7 deletions
+38 -7
View File
@@ -34,7 +34,7 @@ var commandNames = []string{
"add", "done", "modify", "delete",
"start", "stop", "count", "projects", "tags",
"info", "edit", "server", "sync", "reports", "setup",
"version", "annotate", "denotate", "undo", "log",
"version", "annotate", "denotate", "undo", "log", "completion",
}
// Report names (dynamically populated)
@@ -222,31 +222,62 @@ func init() {
initializeApp()
}
// Add regular subcommands
// Command groups for organized help output
rootCmd.AddGroup(
&cobra.Group{ID: "task", Title: "Task Commands:"},
&cobra.Group{ID: "report", Title: "Reports:"},
&cobra.Group{ID: "other", Title: "Other:"},
)
// Task commands
addCmd.GroupID = "task"
doneCmd.GroupID = "task"
modifyCmd.GroupID = "task"
deleteCmd.GroupID = "task"
startCmd.GroupID = "task"
stopCmd.GroupID = "task"
editCmd.GroupID = "task"
infoCmd.GroupID = "task"
annotateCmd.GroupID = "task"
denotateCmd.GroupID = "task"
undoCmd.GroupID = "task"
logCmd.GroupID = "task"
rootCmd.AddCommand(addCmd)
rootCmd.AddCommand(doneCmd)
rootCmd.AddCommand(modifyCmd)
rootCmd.AddCommand(deleteCmd)
rootCmd.AddCommand(startCmd)
rootCmd.AddCommand(stopCmd)
rootCmd.AddCommand(countCmd)
rootCmd.AddCommand(projectsCmd)
rootCmd.AddCommand(tagsCmd)
rootCmd.AddCommand(infoCmd)
rootCmd.AddCommand(editCmd)
rootCmd.AddCommand(reportsCmd)
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(annotateCmd)
rootCmd.AddCommand(denotateCmd)
rootCmd.AddCommand(undoCmd)
rootCmd.AddCommand(logCmd)
// Other commands
countCmd.GroupID = "other"
projectsCmd.GroupID = "other"
tagsCmd.GroupID = "other"
reportsCmd.GroupID = "other"
versionCmd.GroupID = "other"
completionCmd.GroupID = "other"
rootCmd.AddCommand(countCmd)
rootCmd.AddCommand(projectsCmd)
rootCmd.AddCommand(tagsCmd)
rootCmd.AddCommand(reportsCmd)
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(completionCmd)
// Enable --version flag on root command
rootCmd.Version = Version
// Add report commands dynamically
reportCommands := CreateReportCommands()
for _, cmd := range reportCommands {
cmd.GroupID = "report"
rootCmd.AddCommand(cmd)
}
}