1package commands
 2
 3import (
 4	"errors"
 5
 6	"github.com/MichaelMure/git-bug/cache"
 7	"github.com/spf13/cobra"
 8)
 9
10func runCloseBug(cmd *cobra.Command, 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	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.Close()
33	if err != nil {
34		return err
35	}
36
37	return b.Commit()
38}
39
40var closeCmd = &cobra.Command{
41	Use:   "close <id>",
42	Short: "Mark the bug as closed",
43	RunE:  runCloseBug,
44}
45
46func init() {
47	RootCmd.AddCommand(closeCmd)
48}