bug_rm.go

 1package bugcmd
 2
 3import (
 4	"errors"
 5
 6	"github.com/spf13/cobra"
 7
 8	"github.com/MichaelMure/git-bug/commands/completion"
 9	"github.com/MichaelMure/git-bug/commands/execenv"
10)
11
12func newBugRmCommand() *cobra.Command {
13	env := execenv.NewEnv()
14
15	cmd := &cobra.Command{
16		Use:     "rm BUG_ID",
17		Short:   "Remove an existing bug",
18		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.",
19		PreRunE: execenv.LoadBackendEnsureUser(env),
20		RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
21			return runBugRm(env, args)
22		}),
23		ValidArgsFunction: completion.Bug(env),
24	}
25
26	flags := cmd.Flags()
27	flags.SortFlags = false
28
29	return cmd
30}
31
32func runBugRm(env *execenv.Env, args []string) (err error) {
33	if len(args) == 0 {
34		return errors.New("you must provide a bug prefix to remove")
35	}
36
37	err = env.Backend.RemoveBug(args[0])
38
39	if err != nil {
40		return
41	}
42
43	env.Out.Printf("bug %s removed\n", args[0])
44
45	return
46}