MCPcopy Create free account
hub / github.com/git-bug/git-bug / Ls

Function Ls

commands/completion/helper_completion.go:124–200  ·  view source on GitHub ↗
(env *execenv.Env)

Source from the content-addressed store, hash-verified

122}
123
124func Ls(env *execenv.Env) ValidArgsFunction {
125 return func(cmd *cobra.Command, args []string, toComplete string) (completions []string, directives cobra.ShellCompDirective) {
126 if strings.HasPrefix(toComplete, "status:") {
127 completions = append(completions, "status:open\tOpen bugs")
128 completions = append(completions, "status:closed\tClosed bugs")
129 return completions, cobra.ShellCompDirectiveDefault
130 }
131
132 byPerson := []string{"author:", "participant:", "actor:"}
133 byLabel := []string{"label:", "no:"}
134 needBackend := false
135 for _, key := range append(byPerson, byLabel...) {
136 if strings.HasPrefix(toComplete, key) {
137 needBackend = true
138 }
139 }
140
141 if needBackend {
142 if err := execenv.LoadBackend(env)(cmd, args); err != nil {
143 return HandleError(err)
144 }
145 defer func() {
146 _ = env.Backend.Close()
147 }()
148 }
149
150 for _, key := range byPerson {
151 if !strings.HasPrefix(toComplete, key) {
152 continue
153 }
154 ids := env.Backend.Identities().AllIds()
155 completions = make([]string, len(ids))
156 for i, id := range ids {
157 user, err := env.Backend.Identities().ResolveExcerpt(id)
158 if err != nil {
159 return HandleError(err)
160 }
161 var handle string
162 if user.Login != "" {
163 handle = user.Login
164 } else {
165 // "author:John Doe" does not work yet, so use the first name.
166 handle = strings.Split(user.Name, " ")[0]
167 }
168 completions[i] = key + handle + "\t" + user.DisplayName()
169 }
170 return completions, cobra.ShellCompDirectiveNoFileComp
171 }
172
173 for _, key := range byLabel {
174 if !strings.HasPrefix(toComplete, key) {
175 continue
176 }
177 labels := env.Backend.Bugs().ValidLabels()
178 completions = make([]string, len(labels))
179 for i, label := range labels {
180 if strings.Contains(label.String(), " ") {
181 completions[i] = key + "\"" + string(label) + "\""

Callers 1

NewBugCommandFunction · 0.92

Calls 11

LoadBackendFunction · 0.92
HandleErrorFunction · 0.85
AllIdsMethod · 0.80
IdentitiesMethod · 0.80
ResolveExcerptMethod · 0.80
BugsMethod · 0.80
CloseMethod · 0.65
DisplayNameMethod · 0.65
ValidLabelsMethod · 0.65
StringMethod · 0.65
HasPrefixMethod · 0.45

Tested by

no test coverage detected