feb5406077
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>
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
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
|
|
}
|