1package commands
2
3import (
4 "fmt"
5
6 "github.com/MichaelMure/git-bug/cache"
7 "github.com/MichaelMure/git-bug/commands/select"
8 "github.com/MichaelMure/git-bug/util/interrupt"
9 "github.com/spf13/cobra"
10)
11
12func runLabel(cmd *cobra.Command, args []string) error {
13 backend, err := cache.NewRepoCache(repo)
14 if err != nil {
15 return err
16 }
17 defer backend.Close()
18 interrupt.RegisterCleaner(backend.Close)
19
20 b, args, err := _select.ResolveBug(backend, args)
21 if err != nil {
22 return err
23 }
24
25 snap := b.Snapshot()
26
27 for _, l := range snap.Labels {
28 fmt.Println(l)
29 }
30
31 return nil
32}
33
34var labelCmd = &cobra.Command{
35 Use: "label [<id>]",
36 Short: "Display, add or remove labels.",
37 PreRunE: loadRepo,
38 RunE: runLabel,
39}
40
41func init() {
42 RootCmd.AddCommand(labelCmd)
43
44 labelCmd.Flags().SortFlags = false
45}