close.go

 1package commands
 2
 3import (
 4	"errors"
 5	"github.com/MichaelMure/git-bug/bug"
 6	"github.com/MichaelMure/git-bug/bug/operations"
 7	"github.com/MichaelMure/git-bug/repository"
 8)
 9
10func runCloseBug(repo repository.Repo, args []string) error {
11	if len(args) > 1 {
12		return errors.New("Only closing one bug at a time is supported")
13	}
14
15	if len(args) == 0 {
16		return errors.New("You must provide a bug id")
17	}
18
19	prefix := args[0]
20
21	b, err := bug.FindBug(repo, prefix)
22	if err != nil {
23		return err
24	}
25
26	op := operations.NewSetStatusOp(bug.ClosedStatus)
27
28	b.Append(op)
29
30	err = b.Commit(repo)
31
32	return err
33}
34
35var closeCmd = &Command{
36	Description: "Mark the bug as closed",
37	Usage:       "<id>",
38	RunMethod:   runCloseBug,
39}