open.go

 1package commands
 2
 3import (
 4	"errors"
 5
 6	"github.com/MichaelMure/git-bug/bug"
 7	"github.com/MichaelMure/git-bug/bug/operations"
 8	"github.com/spf13/cobra"
 9)
10
11func runOpenBug(cmd *cobra.Command, args []string) error {
12	if len(args) > 1 {
13		return errors.New("Only opening one bug at a time is supported")
14	}
15
16	if len(args) == 0 {
17		return errors.New("You must provide a bug id")
18	}
19
20	prefix := args[0]
21
22	b, err := bug.FindLocalBug(repo, prefix)
23	if err != nil {
24		return err
25	}
26
27	author, err := bug.GetUser(repo)
28	if err != nil {
29		return err
30	}
31
32	operations.Open(b, author)
33
34	return b.Commit(repo)
35}
36
37var openCmd = &cobra.Command{
38	Use:   "open <id>",
39	Short: "Mark the bug as open",
40	RunE:  runOpenBug,
41}
42
43func init() {
44	RootCmd.AddCommand(openCmd)
45}