2018-07-18 17:41:09 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"github.com/MichaelMure/git-bug/bug"
|
|
|
|
"github.com/MichaelMure/git-bug/bug/operations"
|
2018-07-19 13:30:25 +03:00
|
|
|
"github.com/spf13/cobra"
|
2018-07-25 19:01:32 +03:00
|
|
|
"os"
|
2018-07-18 17:41:09 +03:00
|
|
|
)
|
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
var labelRemove bool
|
2018-07-18 17:41:09 +03:00
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
func runLabel(cmd *cobra.Command, args []string) error {
|
2018-07-18 17:41:09 +03:00
|
|
|
if len(args) == 0 {
|
|
|
|
return errors.New("You must provide a bug id")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(args) == 1 {
|
|
|
|
return errors.New("You must provide a label")
|
|
|
|
}
|
|
|
|
|
|
|
|
prefix := args[0]
|
|
|
|
|
2018-07-25 19:01:32 +03:00
|
|
|
var add, remove []string
|
|
|
|
|
|
|
|
if labelRemove {
|
|
|
|
remove = args[1:]
|
|
|
|
} else {
|
|
|
|
add = args[1:]
|
|
|
|
}
|
|
|
|
|
2018-07-23 01:04:46 +03:00
|
|
|
b, err := bug.FindLocalBug(repo, prefix)
|
2018-07-18 17:41:09 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
author, err := bug.GetUser(repo)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-07-25 19:01:32 +03:00
|
|
|
err = operations.ChangeLabels(os.Stdout, b, author, add, remove)
|
2018-07-18 17:41:09 +03:00
|
|
|
|
2018-07-25 19:01:32 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-07-18 17:41:09 +03:00
|
|
|
}
|
|
|
|
|
2018-07-25 19:01:32 +03:00
|
|
|
return b.Commit(repo)
|
2018-07-18 17:41:09 +03:00
|
|
|
}
|
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
var labelCmd = &cobra.Command{
|
|
|
|
Use: "label [<option>...] <id> [<label>...]",
|
|
|
|
Short: "Manipulate bug's label",
|
|
|
|
RunE: runLabel,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2018-07-20 16:46:14 +03:00
|
|
|
RootCmd.AddCommand(labelCmd)
|
2018-07-19 13:30:25 +03:00
|
|
|
|
|
|
|
labelCmd.Flags().BoolVarP(&labelRemove, "remove", "r", false,
|
|
|
|
"Remove a label",
|
|
|
|
)
|
2018-07-18 17:41:09 +03:00
|
|
|
}
|