diff options
author | Michael Muré <batolettre@gmail.com> | 2018-07-25 18:01:32 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-07-25 18:01:32 +0200 |
commit | 6a12373965aff9f80147f8b5bff6a5a104927365 (patch) | |
tree | ccc1e34fba059512acab39286a86f6b73c5ad318 /commands/label.go | |
parent | 49c90eab26875cbf3094d9a546ad29b426e174a1 (diff) | |
download | git-bug-6a12373965aff9f80147f8b5bff6a5a104927365.tar.gz |
more refactoring to have reusable bug action across different UI
Diffstat (limited to 'commands/label.go')
-rw-r--r-- | commands/label.go | 70 |
1 files changed, 13 insertions, 57 deletions
diff --git a/commands/label.go b/commands/label.go index e1679972..ee6ed25f 100644 --- a/commands/label.go +++ b/commands/label.go @@ -2,10 +2,10 @@ package commands import ( "errors" - "fmt" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/bug/operations" "github.com/spf13/cobra" + "os" ) var labelRemove bool @@ -21,6 +21,14 @@ func runLabel(cmd *cobra.Command, args []string) error { prefix := args[0] + var add, remove []string + + if labelRemove { + remove = args[1:] + } else { + add = args[1:] + } + b, err := bug.FindLocalBug(repo, prefix) if err != nil { return err @@ -31,65 +39,13 @@ func runLabel(cmd *cobra.Command, args []string) error { return err } - var added, removed []bug.Label - - snap := b.Compile() - - for _, arg := range args[1:] { - label := bug.Label(arg) - - if labelRemove { - // check for duplicate - if labelExist(removed, label) { - fmt.Printf("label \"%s\" is a duplicate\n", arg) - continue - } - - // check that the label actually exist - if !labelExist(snap.Labels, label) { - fmt.Printf("label \"%s\" doesn't exist on this bug\n", arg) - continue - } - - removed = append(removed, label) - } else { - // check for duplicate - if labelExist(added, label) { - fmt.Printf("label \"%s\" is a duplicate\n", arg) - continue - } - - // check that the label doesn't already exist - if labelExist(snap.Labels, label) { - fmt.Printf("label \"%s\" is already set on this bug\n", arg) - continue - } - - added = append(added, label) - } - } - - if len(added) == 0 && len(removed) == 0 { - return errors.New("no label added or removed") - } - - labelOp := operations.NewLabelChangeOperation(author, added, removed) - - b.Append(labelOp) + err = operations.ChangeLabels(os.Stdout, b, author, add, remove) - err = b.Commit(repo) - - return err -} - -func labelExist(labels []bug.Label, label bug.Label) bool { - for _, l := range labels { - if l == label { - return true - } + if err != nil { + return err } - return false + return b.Commit(repo) } var labelCmd = &cobra.Command{ |