summaryrefslogtreecommitdiffstatshomepage
path: root/commands/label_rm.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-06-28 18:26:29 +0200
committerMichael Muré <batolettre@gmail.com>2020-06-28 18:26:29 +0200
commit26bd1dd11010b4d86cebe2510ad7085a6b316334 (patch)
treef1fe939311c75bd615071e96f3d37822cccd77a7 /commands/label_rm.go
parentc0dbc149d5c0c3610476ba14a800c9ba803a2c2c (diff)
downloadgit-bug-26bd1dd11010b4d86cebe2510ad7085a6b316334.tar.gz
git-bug-26bd1dd11010b4d86cebe2510ad7085a6b316334.zip
commands: refactor to avoid globals
Diffstat (limited to 'commands/label_rm.go')
-rw-r--r--commands/label_rm.go34
1 files changed, 18 insertions, 16 deletions
diff --git a/commands/label_rm.go b/commands/label_rm.go
index 11300c782..5fba41504 100644
--- a/commands/label_rm.go
+++ b/commands/label_rm.go
@@ -1,8 +1,6 @@
package commands
import (
- "fmt"
-
"github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/cache"
@@ -10,8 +8,23 @@ import (
"github.com/MichaelMure/git-bug/util/interrupt"
)
-func runLabelRm(cmd *cobra.Command, args []string) error {
- backend, err := cache.NewRepoCache(repo)
+func newLabelRmCommand() *cobra.Command {
+ env := newEnv()
+
+ cmd := &cobra.Command{
+ Use: "rm [<id>] <label>[...]",
+ Short: "Remove a label from a bug.",
+ PreRunE: loadRepo(env),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runLabelRm(env, args)
+ },
+ }
+
+ return cmd
+}
+
+func runLabelRm(env *Env, args []string) error {
+ backend, err := cache.NewRepoCache(env.repo)
if err != nil {
return err
}
@@ -26,7 +39,7 @@ func runLabelRm(cmd *cobra.Command, args []string) error {
changes, _, err := b.ChangeLabels(nil, args)
for _, change := range changes {
- fmt.Println(change)
+ env.out.Println(change)
}
if err != nil {
@@ -35,14 +48,3 @@ func runLabelRm(cmd *cobra.Command, args []string) error {
return b.Commit()
}
-
-var labelRmCmd = &cobra.Command{
- Use: "rm [<id>] <label>[...]",
- Short: "Remove a label from a bug.",
- PreRunE: loadRepo,
- RunE: runLabelRm,
-}
-
-func init() {
- labelCmd.AddCommand(labelRmCmd)
-}