diff options
-rw-r--r-- | cache/repo_cache_bug.go | 18 | ||||
-rw-r--r-- | commands/rm.go | 45 | ||||
-rw-r--r-- | commands/root.go | 1 |
3 files changed, 64 insertions, 0 deletions
diff --git a/cache/repo_cache_bug.go b/cache/repo_cache_bug.go index 30692363..0492e7f1 100644 --- a/cache/repo_cache_bug.go +++ b/cache/repo_cache_bug.go @@ -359,3 +359,21 @@ func (c *RepoCache) NewBugRaw(author *IdentityCache, unixTime int64, title strin return cached, op, nil } + +// RemoveBug removes a bug from the cache and repo +func (c *RepoCache) RemoveBug(prefix string) error { + b, err := c.ResolveBugPrefix(prefix) + if err != nil { + return err + } + + err = bug.RemoveLocalBug(c.repo, b.Id()) + if err != nil { + return err + } + + delete(c.bugs, b.Id()) + delete(c.bugExcerpts, b.Id()) + + return c.writeBugCache() +} diff --git a/commands/rm.go b/commands/rm.go new file mode 100644 index 00000000..7b34a629 --- /dev/null +++ b/commands/rm.go @@ -0,0 +1,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 +} diff --git a/commands/root.go b/commands/root.go index a67fec1a..e7848363 100644 --- a/commands/root.go +++ b/commands/root.go @@ -71,6 +71,7 @@ _git_bug() { cmd.AddCommand(newLsLabelCommand()) cmd.AddCommand(newPullCommand()) cmd.AddCommand(newPushCommand()) + cmd.AddCommand(newRmCommand()) cmd.AddCommand(newSelectCommand()) cmd.AddCommand(newShowCommand()) cmd.AddCommand(newStatusCommand()) |