label.go

 1package commands
 2
 3import (
 4	"github.com/spf13/cobra"
 5
 6	"github.com/MichaelMure/git-bug/commands/execenv"
 7)
 8
 9func newLabelCommand() *cobra.Command {
10	env := execenv.NewEnv()
11
12	cmd := &cobra.Command{
13		Use:   "label",
14		Short: "List valid labels",
15		Long: `List valid labels.
16
17Note: 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.`,
18		PreRunE: execenv.LoadBackend(env),
19		RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
20			return runLabel(env)
21		}),
22	}
23
24	return cmd
25}
26
27func runLabel(env *execenv.Env) error {
28	labels := env.Backend.Bugs().ValidLabels()
29
30	for _, l := range labels {
31		env.Out.Println(l)
32	}
33
34	return nil
35}