integrate actors and participant filters into ls and show commands

This commit is contained in:
Amine Hilaly 2019-04-05 16:42:45 +02:00
parent 16d2b92f05
commit 14ce66f0dd
2 changed files with 57 additions and 14 deletions

View File

@ -11,13 +11,15 @@ import (
) )
var ( var (
lsStatusQuery []string lsStatusQuery []string
lsAuthorQuery []string lsAuthorQuery []string
lsTitleQuery []string lsParticipantQuery []string
lsLabelQuery []string lsLabelQuery []string
lsNoQuery []string lsTitleQuery []string
lsSortBy string lsActorQuery []string
lsSortDirection string lsNoQuery []string
lsSortBy string
lsSortDirection string
) )
func runLsBug(cmd *cobra.Command, args []string) error { func runLsBug(cmd *cobra.Command, args []string) error {
@ -89,6 +91,16 @@ func lsQueryFromFlags() (*cache.Query, error) {
query.Author = append(query.Author, f) query.Author = append(query.Author, f)
} }
for _, actor := range lsActorQuery {
f := cache.ActorFilter(actor)
query.Actor = append(query.Actor, f)
}
for _, participant := range lsParticipantQuery {
f := cache.ParticipantFilter(participant)
query.Participant = append(query.Participant, f)
}
for _, label := range lsLabelQuery { for _, label := range lsLabelQuery {
f := cache.LabelFilter(label) f := cache.LabelFilter(label)
query.Label = append(query.Label, f) query.Label = append(query.Label, f)
@ -151,6 +163,10 @@ func init() {
"Filter by status. Valid values are [open,closed]") "Filter by status. Valid values are [open,closed]")
lsCmd.Flags().StringSliceVarP(&lsAuthorQuery, "author", "a", nil, lsCmd.Flags().StringSliceVarP(&lsAuthorQuery, "author", "a", nil,
"Filter by author") "Filter by author")
lsCmd.Flags().StringSliceVarP(&lsParticipantQuery, "participant", "p", nil,
"Filter by participant")
lsCmd.Flags().StringSliceVarP(&lsActorQuery, "actor", "A", nil,
"Filter by actor")
lsCmd.Flags().StringSliceVarP(&lsLabelQuery, "label", "l", nil, lsCmd.Flags().StringSliceVarP(&lsLabelQuery, "label", "l", nil,
"Filter by label") "Filter by label")
lsCmd.Flags().StringSliceVarP(&lsTitleQuery, "title", "t", nil, lsCmd.Flags().StringSliceVarP(&lsTitleQuery, "title", "t", nil,

View File

@ -6,7 +6,7 @@ import (
"strings" "strings"
"github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/commands/select" _select "github.com/MichaelMure/git-bug/commands/select"
"github.com/MichaelMure/git-bug/util/colors" "github.com/MichaelMure/git-bug/util/colors"
"github.com/MichaelMure/git-bug/util/interrupt" "github.com/MichaelMure/git-bug/util/interrupt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -50,11 +50,17 @@ func runShowBug(cmd *cobra.Command, args []string) error {
case "id": case "id":
fmt.Printf("%s\n", snapshot.Id()) fmt.Printf("%s\n", snapshot.Id())
case "labels": case "labels":
var labels = make([]string, len(snapshot.Labels)) for _, l := range snapshot.Labels {
for i, l := range snapshot.Labels { fmt.Printf("%s\n", l.String())
labels[i] = string(l) }
case "actors":
for _, a := range snapshot.Actors {
fmt.Printf("%s\n", a.DisplayName())
}
case "participants":
for _, p := range snapshot.Participants {
fmt.Printf("%s\n", p.DisplayName())
} }
fmt.Printf("%s\n", strings.Join(labels, "\n"))
case "shortId": case "shortId":
fmt.Printf("%s\n", snapshot.HumanId()) fmt.Printf("%s\n", snapshot.HumanId())
case "status": case "status":
@ -80,15 +86,36 @@ func runShowBug(cmd *cobra.Command, args []string) error {
firstComment.FormatTimeRel(), firstComment.FormatTimeRel(),
) )
// Labels
var labels = make([]string, len(snapshot.Labels)) var labels = make([]string, len(snapshot.Labels))
for i := range snapshot.Labels { for i := range snapshot.Labels {
labels[i] = string(snapshot.Labels[i]) labels[i] = string(snapshot.Labels[i])
} }
fmt.Printf("labels: %s\n\n", fmt.Printf("labels: %s\n",
strings.Join(labels, ", "), strings.Join(labels, ", "),
) )
// Actors
var actors = make([]string, len(snapshot.Actors))
for i := range snapshot.Actors {
actors[i] = snapshot.Actors[i].DisplayName()
}
fmt.Printf("actors: %s\n",
strings.Join(actors, ", "),
)
// Participants
var participants = make([]string, len(snapshot.Participants))
for i := range snapshot.Participants {
participants[i] = snapshot.Participants[i].DisplayName()
}
fmt.Printf("participants: %s\n\n",
strings.Join(participants, ", "),
)
// Comments // Comments
indent := " " indent := " "
@ -126,5 +153,5 @@ var showCmd = &cobra.Command{
func init() { func init() {
RootCmd.AddCommand(showCmd) RootCmd.AddCommand(showCmd)
showCmd.Flags().StringVarP(&showFieldsQuery, "field", "f", "", showCmd.Flags().StringVarP(&showFieldsQuery, "field", "f", "",
"Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title]") "Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title,actors,participants]")
} }