1package commands
2
3import (
4 "github.com/spf13/cobra"
5
6 "github.com/MichaelMure/git-bug/cache"
7 "github.com/MichaelMure/git-bug/util/interrupt"
8)
9
10func newLsLabelCommand() *cobra.Command {
11 env := newEnv()
12
13 cmd := &cobra.Command{
14 Use: "ls-label",
15 Short: "List valid labels.",
16 Long: `List valid labels.
17
18Note: 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.`,
19 PreRunE: loadRepo(env),
20 RunE: func(cmd *cobra.Command, args []string) error {
21 return runLsLabel(env)
22 },
23 }
24
25 return cmd
26}
27
28func runLsLabel(env *Env) error {
29 backend, err := cache.NewRepoCache(env.repo)
30 if err != nil {
31 return err
32 }
33 defer backend.Close()
34 interrupt.RegisterCleaner(backend.Close)
35
36 labels := backend.ValidLabels()
37
38 for _, l := range labels {
39 env.out.Println(l)
40 }
41
42 return nil
43}