open.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 runOpenBug(repo repository.Repo, args []string) error {
11	if len(args) > 1 {
12		return errors.New("Only opening 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	author, err := bug.GetUser(repo)
27	if err != nil {
28		return err
29	}
30
31	op := operations.NewSetStatusOp(author, bug.OpenStatus)
32
33	b.Append(op)
34
35	err = b.Commit(repo)
36
37	return err
38}
39
40var openCmd = &Command{
41	Description: "Mark the bug as open",
42	Usage:       "<id>",
43	RunMethod:   runOpenBug,
44}