aboutsummaryrefslogtreecommitdiffstats
path: root/commands/rm.go
blob: 7b34a6299f8027092196210518fb0f697c971ff2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package commands

import (
	"fmt"

	"github.com/spf13/cobra"
)

type rmOptions struct {
}

func newRmCommand() *cobra.Command {
	env := newEnv()
	options := rmOptions{}

	cmd := &cobra.Command{
		Use:      "rm <id>",
		Short:    "Remove an existing bug.",
		PreRunE:  loadBackendEnsureUser(env),
		PostRunE: closeBackend(env),
		RunE: func(cmd *cobra.Command, args []string) error {
			return runRm(env, options, args)
		},
	}

	flags := cmd.Flags()
	flags.SortFlags = false

	return cmd
}

func runRm(env *Env, opts rmOptions, args []string) error {
	if len(args) == 0 {
		return fmt.Errorf("you must provide a bug id prefix to remove")
	}

	err := env.backend.RemoveBug(args[0])
	if err != nil {
		return err
	}

	env.out.Printf("bug %s removed\n", args[0])

	return nil
}