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