aboutsummaryrefslogtreecommitdiffstats
path: root/commands/label.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/label.go')
-rw-r--r--commands/label.go40
1 files changed, 22 insertions, 18 deletions
diff --git a/commands/label.go b/commands/label.go
index a07e9efc..e48be18e 100644
--- a/commands/label.go
+++ b/commands/label.go
@@ -1,16 +1,33 @@
package commands
import (
- "fmt"
+ "github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/commands/select"
"github.com/MichaelMure/git-bug/util/interrupt"
- "github.com/spf13/cobra"
)
-func runLabel(cmd *cobra.Command, args []string) error {
- backend, err := cache.NewRepoCache(repo)
+func newLabelCommand() *cobra.Command {
+ env := newEnv()
+
+ cmd := &cobra.Command{
+ Use: "label [<id>]",
+ Short: "Display, add or remove labels to/from a bug.",
+ PreRunE: loadRepo(env),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runLabel(env, args)
+ },
+ }
+
+ cmd.AddCommand(newLabelAddCommand())
+ cmd.AddCommand(newLabelRmCommand())
+
+ return cmd
+}
+
+func runLabel(env *Env, args []string) error {
+ backend, err := cache.NewRepoCache(env.repo)
if err != nil {
return err
}
@@ -25,21 +42,8 @@ func runLabel(cmd *cobra.Command, args []string) error {
snap := b.Snapshot()
for _, l := range snap.Labels {
- fmt.Println(l)
+ env.out.Println(l)
}
return nil
}
-
-var labelCmd = &cobra.Command{
- Use: "label [<id>]",
- Short: "Display, add or remove labels to/from a bug.",
- PreRunE: loadRepo,
- RunE: runLabel,
-}
-
-func init() {
- RootCmd.AddCommand(labelCmd)
-
- labelCmd.Flags().SortFlags = false
-}