1package commands
2
3import (
4 "errors"
5 "github.com/MichaelMure/git-bug/bug"
6 "github.com/MichaelMure/git-bug/bug/operations"
7 "github.com/spf13/cobra"
8 "os"
9)
10
11var labelRemove bool
12
13func runLabel(cmd *cobra.Command, args []string) error {
14 if len(args) == 0 {
15 return errors.New("You must provide a bug id")
16 }
17
18 if len(args) == 1 {
19 return errors.New("You must provide a label")
20 }
21
22 prefix := args[0]
23
24 var add, remove []string
25
26 if labelRemove {
27 remove = args[1:]
28 } else {
29 add = args[1:]
30 }
31
32 b, err := bug.FindLocalBug(repo, prefix)
33 if err != nil {
34 return err
35 }
36
37 author, err := bug.GetUser(repo)
38 if err != nil {
39 return err
40 }
41
42 err = operations.ChangeLabels(os.Stdout, b, author, add, remove)
43
44 if err != nil {
45 return err
46 }
47
48 return b.Commit(repo)
49}
50
51var labelCmd = &cobra.Command{
52 Use: "label [<option>...] <id> [<label>...]",
53 Short: "Manipulate bug's label",
54 RunE: runLabel,
55}
56
57func init() {
58 RootCmd.AddCommand(labelCmd)
59
60 labelCmd.Flags().BoolVarP(&labelRemove, "remove", "r", false,
61 "Remove a label",
62 )
63}