MCPcopy Index your code
hub / github.com/git-bug/git-bug / UserForQuery

Function UserForQuery

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

Source from the content-addressed store, hash-verified

222}
223
224func UserForQuery(env *execenv.Env) ValidArgsFunction {
225 return func(cmd *cobra.Command, args []string, toComplete string) (completions []string, directives cobra.ShellCompDirective) {
226 if err := execenv.LoadBackend(env)(cmd, args); err != nil {
227 return HandleError(err)
228 }
229 defer func() {
230 _ = env.Backend.Close()
231 }()
232
233 ids := env.Backend.Identities().AllIds()
234 completions = make([]string, len(ids))
235 for i, id := range ids {
236 user, err := env.Backend.Identities().ResolveExcerpt(id)
237 if err != nil {
238 return HandleError(err)
239 }
240 var handle string
241 if user.Login != "" {
242 handle = user.Login
243 } else {
244 // "author:John Doe" does not work yet, so use the first name.
245 handle = strings.Split(user.Name, " ")[0]
246 }
247 completions[i] = handle + "\t" + user.DisplayName()
248 }
249 return completions, cobra.ShellCompDirectiveNoFileComp
250 }
251}

Callers 1

NewBugCommandFunction · 0.92

Calls 7

LoadBackendFunction · 0.92
HandleErrorFunction · 0.85
AllIdsMethod · 0.80
IdentitiesMethod · 0.80
ResolveExcerptMethod · 0.80
CloseMethod · 0.65
DisplayNameMethod · 0.65

Tested by

no test coverage detected