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/spf13/cobra"
 8)
 9
10func runOpenBug(cmd *cobra.Command, 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 = &cobra.Command{
41	Use:   "open <id>",
42	Short: "Mark the bug as open",
43	RunE:  runOpenBug,
44}
45
46func init() {
47	rootCmd.AddCommand(openCmd)
48}