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

Function completeQuery

commands/bug/bug.go:359–414  ·  view source on GitHub ↗

Finish the command flags transformation into the query.Query

(q *query.Query, opts bugOptions)

Source from the content-addressed store, hash-verified

357
358// Finish the command flags transformation into the query.Query
359func completeQuery(q *query.Query, opts bugOptions) error {
360 for _, str := range opts.statusQuery {
361 status, err := common.StatusFromString(str)
362 if err != nil {
363 return err
364 }
365 q.Status = append(q.Status, status)
366 }
367
368 q.Author = append(q.Author, opts.authorQuery...)
369 for _, str := range opts.metadataQuery {
370 tokens := strings.Split(str, "=")
371 if len(tokens) < 2 {
372 return fmt.Errorf("no \"=\" in key=value metadata markup")
373 }
374 var pair query.StringPair
375 pair.Key = tokens[0]
376 pair.Value = tokens[1]
377 q.Metadata = append(q.Metadata, pair)
378 }
379 q.Participant = append(q.Participant, opts.participantQuery...)
380 q.Actor = append(q.Actor, opts.actorQuery...)
381 q.Label = append(q.Label, opts.labelQuery...)
382 q.Title = append(q.Title, opts.titleQuery...)
383
384 for _, no := range opts.noQuery {
385 switch no {
386 case "label":
387 q.NoLabel = true
388 default:
389 return fmt.Errorf("unknown \"no\" filter %s", no)
390 }
391 }
392
393 switch opts.sortBy {
394 case "id":
395 q.OrderBy = query.OrderById
396 case "creation":
397 q.OrderBy = query.OrderByCreation
398 case "edit":
399 q.OrderBy = query.OrderByEdit
400 default:
401 return fmt.Errorf("unknown sort flag %s", opts.sortBy)
402 }
403
404 switch opts.sortDirection {
405 case "asc":
406 q.OrderDirection = query.OrderAscending
407 case "desc":
408 q.OrderDirection = query.OrderDescending
409 default:
410 return fmt.Errorf("unknown sort direction %s", opts.sortDirection)
411 }
412
413 return nil
414}

Callers 1

runBugFunction · 0.85

Calls 2

StatusFromStringFunction · 0.92
ErrorfMethod · 0.80

Tested by

no test coverage detected