From 8494b273ddab00bb98d5f63290786c04136dbe5e Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Wed, 7 Oct 2020 20:06:29 +0200 Subject: [PATCH] Adds published-only flag to the list command --- cmd/list.go | 10 ++++++++-- model/campaign.go | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/list.go b/cmd/list.go index 6cd99f0..063c345 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -7,15 +7,21 @@ import ( ) func ListCmd() *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "list", Short: "Prints a list of the campaign's tickets", Long: "Prints a list of the campaign's tickets with their statuses and external ids", Args: cobra.NoArgs, Run: withApp(listCmdF), } + + cmd.Flags().BoolP("published-only", "p", false, "list only published tickets") + + return cmd } func listCmdF(a *app.App, cmd *cobra.Command, _ []string) { - a.Campaign.PrintList() + publishedOnly, _ := cmd.Flags().GetBool("published-only") + + a.Campaign.PrintList(publishedOnly) } diff --git a/model/campaign.go b/model/campaign.go index 9de5fbb..7940ca0 100644 --- a/model/campaign.go +++ b/model/campaign.go @@ -88,7 +88,7 @@ func (c *Campaign) PrintStatus() { w.Flush() } -func (c *Campaign) PrintList() { +func (c *Campaign) PrintList(publishedOnly bool) { for _, t := range c.Tickets { if t.IsPublishedJira() { var str string @@ -101,7 +101,7 @@ func (c *Campaign) PrintList() { str += fmt.Sprintf(" (%s)", color.MagentaString(t.GithubStatus)) } fmt.Println(str) - } else { + } else if !publishedOnly { b, _ := json.Marshal(t) fmt.Printf("unpublished: %s\n", color.YellowString(string(b))) }