Skip to content
Snippets Groups Projects
Unverified Commit 449f7036 authored by Michael Muré's avatar Michael Muré
Browse files

WIP

parent ccb71fea
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ func newCommentEditCommand() *cobra.Command { ...@@ -24,6 +24,7 @@ func newCommentEditCommand() *cobra.Command {
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
return runCommentEdit(env, options, args) return runCommentEdit(env, options, args)
}), }),
ValidArgsFunction: completeComment(env),
} }
flags := cmd.Flags() flags := cmd.Flags()
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"sort" "sort"
"strings" "strings"
text "github.com/MichaelMure/go-term-text"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/bridge" "github.com/MichaelMure/git-bug/bridge"
...@@ -12,6 +13,7 @@ import ( ...@@ -12,6 +13,7 @@ import (
"github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/cache"
_select "github.com/MichaelMure/git-bug/commands/select" _select "github.com/MichaelMure/git-bug/commands/select"
"github.com/MichaelMure/git-bug/entities/bug" "github.com/MichaelMure/git-bug/entities/bug"
"github.com/MichaelMure/git-bug/entity"
) )
type validArgsFunction func(cmd *cobra.Command, args []string, toComplete string) (completions []string, directives cobra.ShellCompDirective) type validArgsFunction func(cmd *cobra.Command, args []string, toComplete string) (completions []string, directives cobra.ShellCompDirective)
...@@ -162,6 +164,47 @@ func completeBugAndLabels(env *Env, addOrRemove bool) validArgsFunction { ...@@ -162,6 +164,47 @@ func completeBugAndLabels(env *Env, addOrRemove bool) validArgsFunction {
} }
} }
func completeComment(env *Env) validArgsFunction {
return func(cmd *cobra.Command, args []string, toComplete string) (completions []string, directives cobra.ShellCompDirective) {
if err := loadBackend(env)(cmd, args); err != nil {
return completionHandlerError(err)
}
defer func() {
_ = env.backend.Close()
}()
bugPrefix, _ := entity.SeparateIds(toComplete)
bugCandidate := make([]entity.Id, 0, 5)
// build a list of possible matching bugs
_, _ = env.backend.ResolveBugExcerptMatcher(func(excerpt *cache.BugExcerpt) bool {
if excerpt.Id.HasPrefix(bugPrefix) {
bugCandidate = append(bugCandidate, excerpt.Id)
}
return false
})
completions = make([]string, 0, 5)
for _, bugId := range bugCandidate {
b, err := env.backend.ResolveBug(bugId)
if err != nil {
return completionHandlerError(err)
}
for _, comment := range b.Snapshot().Comments {
if comment.CombinedId().HasPrefix(toComplete) {
text.TrimSpace()
message := strings.ReplaceAll(comment.Message, "\n", "")
completions = append(completions, comment.CombinedId().Human()+"\t"+text.TruncateMax())
}
}
}
}
}
func completeFrom(choices []string) validArgsFunction { func completeFrom(choices []string) validArgsFunction {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return choices, cobra.ShellCompDirectiveNoFileComp return choices, cobra.ShellCompDirectiveNoFileComp
......
...@@ -50,3 +50,7 @@ func (c Comment) FormatTime() string { ...@@ -50,3 +50,7 @@ func (c Comment) FormatTime() string {
// IsAuthored is a sign post method for gqlgen // IsAuthored is a sign post method for gqlgen
func (c Comment) IsAuthored() {} func (c Comment) IsAuthored() {}
func (c Comment) Shortened(len int) {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment