status_open.go

 1package commands
 2
 3import (
 4	"errors"
 5
 6	"github.com/MichaelMure/git-bug/cache"
 7	"github.com/spf13/cobra"
 8)
 9
10func runStatusOpen(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	backend, err := cache.NewRepoCache(repo)
20	if err != nil {
21		return err
22	}
23	defer backend.Close()
24
25	prefix := args[0]
26
27	b, err := backend.ResolveBugPrefix(prefix)
28	if err != nil {
29		return err
30	}
31
32	err = b.Open()
33	if err != nil {
34		return err
35	}
36
37	return b.Commit()
38}
39
40var openCmd = &cobra.Command{
41	Use:   "open <id>",
42	Short: "Mark the bug as open",
43	RunE:  runStatusOpen,
44}
45
46func init() {
47	statusCmd.AddCommand(openCmd)
48}