From acc9a6f3a6df2961c3ae44352216d915cb9b5315 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 10 Sep 2022 11:09:19 +0200 Subject: commands: reorg into different packages --- commands/bug/bug_rm.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 commands/bug/bug_rm.go (limited to 'commands/bug/bug_rm.go') diff --git a/commands/bug/bug_rm.go b/commands/bug/bug_rm.go new file mode 100644 index 00000000..1d2a7524 --- /dev/null +++ b/commands/bug/bug_rm.go @@ -0,0 +1,46 @@ +package bugcmd + +import ( + "errors" + + "github.com/spf13/cobra" + + "github.com/MichaelMure/git-bug/commands/completion" + "github.com/MichaelMure/git-bug/commands/execenv" +) + +func newBugRmCommand() *cobra.Command { + env := execenv.NewEnv() + + cmd := &cobra.Command{ + Use: "rm BUG_ID", + Short: "Remove an existing bug", + 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.", + PreRunE: execenv.LoadBackendEnsureUser(env), + RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error { + return runBugRm(env, args) + }), + ValidArgsFunction: completion.Bug(env), + } + + flags := cmd.Flags() + flags.SortFlags = false + + return cmd +} + +func runBugRm(env *execenv.Env, args []string) (err error) { + if len(args) == 0 { + return errors.New("you must provide a bug prefix to remove") + } + + err = env.Backend.RemoveBug(args[0]) + + if err != nil { + return + } + + env.Out.Printf("bug %s removed\n", args[0]) + + return +} -- cgit