(env *execenv.Env)
| 222 | } |
| 223 | |
| 224 | func 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 | } |
no test coverage detected