1package bugcmd
 2
 3import (
 4	"errors"
 5
 6	"github.com/spf13/cobra"
 7
 8	"github.com/git-bug/git-bug/commands/execenv"
 9)
10
11func newBugRmCommand(env *execenv.Env) *cobra.Command {
12	cmd := &cobra.Command{
13		Use:     "rm BUG_ID",
14		Short:   "Remove an existing bug",
15		Long:    "Remove an existing bug in the local repository. Note removing bugs that were imported from bridges will not remove the bug on the remote, and will only remove the local copy of the bug.",
16		PreRunE: execenv.LoadBackendEnsureUser(env),
17		RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
18			return runBugRm(env, args)
19		}),
20		ValidArgsFunction: BugCompletion(env),
21	}
22
23	flags := cmd.Flags()
24	flags.SortFlags = false
25
26	return cmd
27}
28
29func runBugRm(env *execenv.Env, args []string) (err error) {
30	if len(args) == 0 {
31		return errors.New("you must provide a bug prefix to remove")
32	}
33
34	err = env.Backend.Bugs().Remove(args[0])
35
36	if err != nil {
37		return
38	}
39
40	env.Out.Printf("bug %s removed\n", args[0])
41
42	return
43}