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:
@@ -0,0 +1,50 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.jnss.me/joakim/opal/internal/engine"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// taskFilterCompletion provides dynamic completions for task filter arguments.
|
||||
// Suggests +tag and project:name completions from the database.
|
||||
func taskFilterCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
var completions []string
|
||||
|
||||
tags, err := engine.GetAllTags()
|
||||
if err == nil {
|
||||
for _, tag := range tags {
|
||||
completions = append(completions, fmt.Sprintf("+%s", tag))
|
||||
}
|
||||
}
|
||||
|
||||
projects, err := engine.GetAllProjects()
|
||||
if err == nil {
|
||||
for _, proj := range projects {
|
||||
completions = append(completions, fmt.Sprintf("project:%s", proj))
|
||||
}
|
||||
}
|
||||
|
||||
// Add known attribute keys
|
||||
for key := range engine.ValidAttributeKeys {
|
||||
completions = append(completions, fmt.Sprintf("%s:", key))
|
||||
}
|
||||
|
||||
return completions, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Register dynamic completions for commands that accept filters
|
||||
addCmd.ValidArgsFunction = taskFilterCompletion
|
||||
doneCmd.ValidArgsFunction = taskFilterCompletion
|
||||
deleteCmd.ValidArgsFunction = taskFilterCompletion
|
||||
modifyCmd.ValidArgsFunction = taskFilterCompletion
|
||||
startCmd.ValidArgsFunction = taskFilterCompletion
|
||||
stopCmd.ValidArgsFunction = taskFilterCompletion
|
||||
editCmd.ValidArgsFunction = taskFilterCompletion
|
||||
infoCmd.ValidArgsFunction = taskFilterCompletion
|
||||
annotateCmd.ValidArgsFunction = taskFilterCompletion
|
||||
denotateCmd.ValidArgsFunction = taskFilterCompletion
|
||||
logCmd.ValidArgsFunction = taskFilterCompletion
|
||||
}
|
||||
Reference in New Issue
Block a user