aboutsummaryrefslogtreecommitdiffstats
path: root/commands/ls-labels.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/ls-labels.go')
-rw-r--r--commands/ls-labels.go44
1 files changed, 19 insertions, 25 deletions
diff --git a/commands/ls-labels.go b/commands/ls-labels.go
index 5610fb56..a7c2fb6f 100644
--- a/commands/ls-labels.go
+++ b/commands/ls-labels.go
@@ -1,40 +1,34 @@
package commands
import (
- "fmt"
-
- "github.com/MichaelMure/git-bug/cache"
- "github.com/MichaelMure/git-bug/util/interrupt"
"github.com/spf13/cobra"
)
-func runLsLabel(cmd *cobra.Command, args []string) error {
- backend, err := cache.NewRepoCache(repo)
- if err != nil {
- return err
- }
- defer backend.Close()
- interrupt.RegisterCleaner(backend.Close)
+func newLsLabelCommand() *cobra.Command {
+ env := newEnv()
- labels := backend.ValidLabels()
+ cmd := &cobra.Command{
+ Use: "ls-label",
+ Short: "List valid labels.",
+ Long: `List valid labels.
- for _, l := range labels {
- fmt.Println(l)
+Note: in the future, a proper label policy could be implemented where valid labels are defined in a configuration file. Until that, the default behavior is to return the list of labels already used.`,
+ PreRunE: loadBackend(env),
+ PostRunE: closeBackend(env),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runLsLabel(env)
+ },
}
- return nil
+ return cmd
}
-var lsLabelCmd = &cobra.Command{
- Use: "ls-label",
- Short: "List valid labels.",
- Long: `List valid labels.
+func runLsLabel(env *Env) error {
+ labels := env.backend.ValidLabels()
-Note: in the future, a proper label policy could be implemented where valid labels are defined in a configuration file. Until that, the default behavior is to return the list of labels already used.`,
- PreRunE: loadRepo,
- RunE: runLsLabel,
-}
+ for _, l := range labels {
+ env.out.Println(l)
+ }
-func init() {
- RootCmd.AddCommand(lsLabelCmd)
+ return nil
}