git-bug/commands/label.go

64 lines
1.0 KiB
Go
Raw Normal View History

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"
"github.com/spf13/cobra"
"os"
2018-07-18 17:41:09 +03:00
)
var labelRemove bool
2018-07-18 17:41:09 +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]
var add, remove []string
if labelRemove {
remove = args[1:]
} else {
add = args[1:]
}
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
}
err = operations.ChangeLabels(os.Stdout, b, author, add, remove)
2018-07-18 17:41:09 +03:00
if err != nil {
return err
2018-07-18 17:41:09 +03:00
}
return b.Commit(repo)
2018-07-18 17:41:09 +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)
labelCmd.Flags().BoolVarP(&labelRemove, "remove", "r", false,
"Remove a label",
)
2018-07-18 17:41:09 +03:00
}