1package bugcmd
2
3import (
4 "github.com/spf13/cobra"
5
6 "github.com/MichaelMure/git-bug/commands/execenv"
7)
8
9func newBugLabelCommand() *cobra.Command {
10 env := execenv.NewEnv()
11
12 cmd := &cobra.Command{
13 Use: "label [BUG_ID]",
14 Short: "Display labels of a bug",
15 PreRunE: execenv.LoadBackend(env),
16 RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
17 return runBugLabel(env, args)
18 }),
19 ValidArgsFunction: BugCompletion(env),
20 }
21
22 cmd.AddCommand(newBugLabelNewCommand())
23 cmd.AddCommand(newBugLabelRmCommand())
24
25 return cmd
26}
27
28func runBugLabel(env *execenv.Env, args []string) error {
29 b, args, err := ResolveSelected(env.Backend, args)
30 if err != nil {
31 return err
32 }
33
34 snap := b.Snapshot()
35
36 for _, l := range snap.Labels {
37 env.Out.Println(l)
38 }
39
40 return nil
41}