aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-21 14:02:05 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-21 14:02:05 +0200
commit6e4475941309b1b8aed7415b948ba6d26d80dfad (patch)
tree727a761970b6a7cbc3558918e253616843a1422f /commands
parentcfce3a9914c4a7762399119fabc63c77f567d7cf (diff)
downloadgit-bug-6e4475941309b1b8aed7415b948ba6d26d80dfad.tar.gz
commands: add a "ls-labels" command that output valid labels
Diffstat (limited to 'commands')
-rw-r--r--commands/ls-labels.go37
1 files changed, 37 insertions, 0 deletions
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)
+}