diff options
Diffstat (limited to 'commands')
-rw-r--r-- | commands/ls.go | 76 |
1 files changed, 28 insertions, 48 deletions
diff --git a/commands/ls.go b/commands/ls.go index aff56f61..f125d916 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -10,21 +10,17 @@ import ( "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/query" - "github.com/MichaelMure/git-bug/query/ast" "github.com/MichaelMure/git-bug/util/colors" "github.com/MichaelMure/git-bug/util/interrupt" ) var ( - lsStatusQuery []string - lsAuthorQuery []string - lsParticipantQuery []string - lsLabelQuery []string - lsTitleQuery []string - lsActorQuery []string - lsNoQuery []string - lsSortBy string - lsSortDirection string + lsQuery query.Query + + lsStatusQuery []string + lsNoQuery []string + lsSortBy string + lsSortDirection string ) func runLsBug(cmd *cobra.Command, args []string) error { @@ -35,7 +31,7 @@ func runLsBug(cmd *cobra.Command, args []string) error { defer backend.Close() interrupt.RegisterCleaner(backend.Close) - var q *ast.Query + var q *query.Query if len(args) >= 1 { q, err = query.Parse(strings.Join(args, " ")) @@ -43,10 +39,11 @@ func runLsBug(cmd *cobra.Command, args []string) error { return err } } else { - q, err = lsQueryFromFlags() + err = completeQuery() if err != nil { return err } + q = &lsQuery } allIds := backend.QueryBugs(q) @@ -99,63 +96,46 @@ func runLsBug(cmd *cobra.Command, args []string) error { return nil } -// Transform the command flags into an ast.Query -func lsQueryFromFlags() (*ast.Query, error) { - q := ast.NewQuery() - +// Finish the command flags transformation into the query.Query +func completeQuery() error { for _, str := range lsStatusQuery { status, err := bug.StatusFromString(str) if err != nil { - return nil, err + return err } - q.Status = append(q.Status, status) - } - for _, title := range lsTitleQuery { - q.Title = append(q.Title, title) - } - for _, author := range lsAuthorQuery { - q.Author = append(q.Author, author) - } - for _, actor := range lsActorQuery { - q.Actor = append(q.Actor, actor) - } - for _, participant := range lsParticipantQuery { - q.Participant = append(q.Participant, participant) - } - for _, label := range lsLabelQuery { - q.Label = append(q.Label, label) + lsQuery.Status = append(lsQuery.Status, status) } for _, no := range lsNoQuery { switch no { case "label": - q.NoLabel = true + lsQuery.NoLabel = true default: - return nil, fmt.Errorf("unknown \"no\" filter %s", no) + return fmt.Errorf("unknown \"no\" filter %s", no) } } switch lsSortBy { case "id": - q.OrderBy = ast.OrderById + lsQuery.OrderBy = query.OrderById case "creation": - q.OrderBy = ast.OrderByCreation + lsQuery.OrderBy = query.OrderByCreation case "edit": - q.OrderBy = ast.OrderByEdit + lsQuery.OrderBy = query.OrderByEdit default: - return nil, fmt.Errorf("unknown sort flag %s", lsSortBy) + return fmt.Errorf("unknown sort flag %s", lsSortBy) } switch lsSortDirection { case "asc": - q.OrderDirection = ast.OrderAscending + lsQuery.OrderDirection = query.OrderAscending case "desc": - q.OrderDirection = ast.OrderDescending + lsQuery.OrderDirection = query.OrderDescending default: - return nil, fmt.Errorf("unknown sort direction %s", lsSortDirection) + return fmt.Errorf("unknown sort direction %s", lsSortDirection) } - return q, nil + return nil } var lsCmd = &cobra.Command{ @@ -181,15 +161,15 @@ func init() { lsCmd.Flags().StringSliceVarP(&lsStatusQuery, "status", "s", nil, "Filter by status. Valid values are [open,closed]") - lsCmd.Flags().StringSliceVarP(&lsAuthorQuery, "author", "a", nil, + lsCmd.Flags().StringSliceVarP(&lsQuery.Author, "author", "a", nil, "Filter by author") - lsCmd.Flags().StringSliceVarP(&lsParticipantQuery, "participant", "p", nil, + lsCmd.Flags().StringSliceVarP(&lsQuery.Participant, "participant", "p", nil, "Filter by participant") - lsCmd.Flags().StringSliceVarP(&lsActorQuery, "actor", "A", nil, + lsCmd.Flags().StringSliceVarP(&lsQuery.Actor, "actor", "A", nil, "Filter by actor") - lsCmd.Flags().StringSliceVarP(&lsLabelQuery, "label", "l", nil, + lsCmd.Flags().StringSliceVarP(&lsQuery.Label, "label", "l", nil, "Filter by label") - lsCmd.Flags().StringSliceVarP(&lsTitleQuery, "title", "t", nil, + lsCmd.Flags().StringSliceVarP(&lsQuery.Title, "title", "t", nil, "Filter by title") lsCmd.Flags().StringSliceVarP(&lsNoQuery, "no", "n", nil, "Filter by absence of something. Valid values are [label]") |