1package commands
2
3import (
4 "errors"
5 "fmt"
6
7 "github.com/MichaelMure/git-bug/cache"
8 "github.com/spf13/cobra"
9)
10
11func runLabel(cmd *cobra.Command, args []string) error {
12 if len(args) > 1 {
13 return errors.New("Only one bug id is supported")
14 }
15
16 if len(args) == 0 {
17 return errors.New("You must provide a bug id")
18 }
19
20 backend, err := cache.NewRepoCache(repo)
21 if err != nil {
22 return err
23 }
24 defer backend.Close()
25
26 prefix := args[0]
27
28 b, err := backend.ResolveBugPrefix(prefix)
29 if err != nil {
30 return err
31 }
32
33 snap := b.Snapshot()
34
35 for _, l := range snap.Labels {
36 fmt.Println(l)
37 }
38
39 return nil
40}
41
42var labelCmd = &cobra.Command{
43 Use: "label <id>",
44 Short: "Display a bug labels",
45 RunE: runLabel,
46}
47
48func init() {
49 RootCmd.AddCommand(labelCmd)
50
51 labelCmd.Flags().SortFlags = false
52}