Add file-only mode to the add command
This commit is contained in:
parent
d5778abbd6
commit
61091e08e5
3 changed files with 12 additions and 4 deletions
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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{}
|
||||
|
|
Loading…
Reference in a new issue