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 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	prefix := args[0]
20
21	b, err := bug.FindLocalBug(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	operations.Close(b, author)
32
33	return b.Commit(repo)
34}
35
36var closeCmd = &cobra.Command{
37	Use:   "close <id>",
38	Short: "Mark the bug as closed",
39	RunE:  runCloseBug,
40}
41
42func init() {
43	RootCmd.AddCommand(closeCmd)
44}