From 61091e08e559c291d99ca21b3a1752f1d813f123 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Sun, 1 Mar 2020 13:21:10 +0100 Subject: [PATCH] Add file-only mode to the add command --- README.md | 2 +- cmd/add.go | 4 +++- model/ticket.go | 10 ++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2d8c730..5c8339d 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Use "campaigner [command] --help" for more information about a command. input. - [x] Add `standalone` group of commands. - [ ] Parametrise the atlassian API url. -- [ ] Add file only mode to the `add` command. +- [x] Add file only mode to the `add` command. - [ ] Add file path normalisation to the `add` command. - [ ] Add `--ag` to the `add` command. - [ ] Add the `publish` command. diff --git a/cmd/add.go b/cmd/add.go index 9603c00..3f8f189 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -31,6 +31,7 @@ func AddCmd() *cobra.Command { cmd.Flags().BoolP("ag", "a", false, "generates the tickets reading ag's output from stdin") cmd.Flags().BoolP("grep", "g", false, "generates the tickets reading grep's output from stdin") cmd.Flags().BoolP("govet", "v", false, "generates the tickets reading govet's output from stdin") + cmd.Flags().BoolP("file-only", "f", false, "generates one ticket per file instead of per match") return cmd } @@ -73,6 +74,7 @@ func addCmdF(cmd *cobra.Command, _ []string) error { grep, _ := cmd.Flags().GetBool("grep") ag, _ := cmd.Flags().GetBool("ag") govet, _ := cmd.Flags().GetBool("govet") + fileOnly, _ := cmd.Flags().GetBool("file-only") if !grep && !ag && !govet { return fmt.Errorf("one of --grep --ag --govet flags should be active") @@ -92,7 +94,7 @@ func addCmdF(cmd *cobra.Command, _ []string) error { } cmp.Tickets = append(cmp.Tickets, tickets...) - cmp.Tickets = model.RemoveDuplicateTickets(cmp.Tickets) + cmp.Tickets = model.RemoveDuplicateTickets(cmp.Tickets, fileOnly) if err := campaign.Save(cmp); err != nil { ErrorAndExit(cmd, err) diff --git a/model/ticket.go b/model/ticket.go index 3aa0e7d..73479d9 100644 --- a/model/ticket.go +++ b/model/ticket.go @@ -10,10 +10,16 @@ type Ticket struct { Text string `json:"text"` } -func RemoveDuplicateTickets(tickets []*Ticket) []*Ticket { +func RemoveDuplicateTickets(tickets []*Ticket, fileOnly bool) []*Ticket { ticketMap := map[string]*Ticket{} for _, t := range tickets { - ticketMap[fmt.Sprintf("%s:%d", t.Filename, t.LineNo)] = t + if fileOnly { + t.Text = "" + t.LineNo = 0 + ticketMap[t.Filename] = t + } else { + ticketMap[fmt.Sprintf("%s:%d", t.Filename, t.LineNo)] = t + } } cleanTickets := []*Ticket{}