2018-07-18 17:41:09 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2020-06-28 19:26:29 +03:00
|
|
|
"github.com/spf13/cobra"
|
2018-08-13 19:32:11 +03:00
|
|
|
|
2022-09-10 12:09:19 +03:00
|
|
|
"github.com/MichaelMure/git-bug/commands/execenv"
|
2018-07-18 17:41:09 +03:00
|
|
|
)
|
|
|
|
|
2020-06-28 19:26:29 +03:00
|
|
|
func newLabelCommand() *cobra.Command {
|
2022-09-10 12:09:19 +03:00
|
|
|
env := execenv.NewEnv()
|
2020-06-28 19:26:29 +03:00
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
2022-09-10 12:09:19 +03:00
|
|
|
Use: "label",
|
|
|
|
Short: "List valid labels",
|
|
|
|
Long: `List valid labels.
|
|
|
|
|
|
|
|
Note: 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.`,
|
|
|
|
PreRunE: execenv.LoadBackend(env),
|
|
|
|
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
|
|
|
|
return runLabel(env)
|
2021-05-09 12:33:20 +03:00
|
|
|
}),
|
2020-06-28 19:26:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2022-09-10 12:09:19 +03:00
|
|
|
func runLabel(env *execenv.Env) error {
|
2022-12-21 23:54:36 +03:00
|
|
|
labels := env.Backend.Bugs().ValidLabels()
|
2018-09-13 13:20:28 +03:00
|
|
|
|
2022-09-10 12:09:19 +03:00
|
|
|
for _, l := range labels {
|
|
|
|
env.Out.Println(l)
|
2018-07-18 17:41:09 +03:00
|
|
|
}
|
|
|
|
|
2018-09-17 15:32:33 +03:00
|
|
|
return nil
|
2018-07-18 17:41:09 +03:00
|
|
|
}
|