From 6e4475941309b1b8aed7415b948ba6d26d80dfad Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Fri, 21 Sep 2018 14:02:05 +0200 Subject: commands: add a "ls-labels" command that output valid labels --- commands/ls-labels.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 commands/ls-labels.go (limited to 'commands') diff --git a/commands/ls-labels.go b/commands/ls-labels.go new file mode 100644 index 00000000..49f4c7cb --- /dev/null +++ b/commands/ls-labels.go @@ -0,0 +1,37 @@ +package commands + +import ( + "fmt" + + "github.com/MichaelMure/git-bug/cache" + "github.com/spf13/cobra" +) + +func runLsLabel(cmd *cobra.Command, args []string) error { + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + + labels := backend.ValidLabels() + + for _, l := range labels { + fmt.Println(l) + } + + return nil +} + +var lsLabelCmd = &cobra.Command{ + Use: "ls-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.`, + RunE: runLsLabel, +} + +func init() { + RootCmd.AddCommand(lsLabelCmd) +} -- cgit