aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cache/repo_cache.go30
-rw-r--r--commands/ls-labels.go37
-rw-r--r--doc/man/git-bug-ls-label.132
-rw-r--r--doc/man/git-bug.12
-rw-r--r--doc/md/git-bug.md1
-rw-r--r--doc/md/git-bug_ls-label.md24
-rw-r--r--misc/bash_completion/git-bug21
-rw-r--r--misc/zsh_completion/git-bug2
8 files changed, 147 insertions, 2 deletions
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index 7ae8bb1d..26f2855f 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -281,6 +281,36 @@ func (c *RepoCache) ClearAllBugs() {
c.bugs = make(map[string]*BugCache)
}
+// ValidLabels 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.
+func (c *RepoCache) ValidLabels() []bug.Label {
+ set := map[bug.Label]interface{}{}
+
+ for _, excerpt := range c.excerpts {
+ for _, l := range excerpt.Labels {
+ set[l] = nil
+ }
+ }
+
+ result := make([]bug.Label, len(set))
+
+ i := 0
+ for l := range set {
+ result[i] = l
+ i++
+ }
+
+ // Sort
+ sort.Slice(result, func(i, j int) bool {
+ return string(result[i]) < string(result[j])
+ })
+
+ return result
+}
+
// NewBug create a new bug
// The new bug is written in the repository (commit)
func (c *RepoCache) NewBug(title string, message string) (*BugCache, error) {
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)
+}
diff --git a/doc/man/git-bug-ls-label.1 b/doc/man/git-bug-ls-label.1
new file mode 100644
index 00000000..01cbf4e7
--- /dev/null
+++ b/doc/man/git-bug-ls-label.1
@@ -0,0 +1,32 @@
+.TH "GIT-BUG" "1" "Sep 2018" "Generated from git-bug's source code" ""
+.nh
+.ad l
+
+
+.SH NAME
+.PP
+git\-bug\-ls\-label \- List valid labels
+
+
+.SH SYNOPSIS
+.PP
+\fBgit\-bug ls\-label [flags]\fP
+
+
+.SH DESCRIPTION
+.PP
+List valid labels.
+
+.PP
+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.
+
+
+.SH OPTIONS
+.PP
+\fB\-h\fP, \fB\-\-help\fP[=false]
+ help for ls\-label
+
+
+.SH SEE ALSO
+.PP
+\fBgit\-bug(1)\fP
diff --git a/doc/man/git-bug.1 b/doc/man/git-bug.1
index 45435773..41a29799 100644
--- a/doc/man/git-bug.1
+++ b/doc/man/git-bug.1
@@ -29,4 +29,4 @@ It use the same internal storage so it doesn't pollute your project. As you woul
.SH SEE ALSO
.PP
-\fBgit\-bug\-add(1)\fP, \fBgit\-bug\-commands(1)\fP, \fBgit\-bug\-comment(1)\fP, \fBgit\-bug\-label(1)\fP, \fBgit\-bug\-ls(1)\fP, \fBgit\-bug\-pull(1)\fP, \fBgit\-bug\-push(1)\fP, \fBgit\-bug\-select(1)\fP, \fBgit\-bug\-show(1)\fP, \fBgit\-bug\-status(1)\fP, \fBgit\-bug\-termui(1)\fP, \fBgit\-bug\-title(1)\fP, \fBgit\-bug\-webui(1)\fP
+\fBgit\-bug\-add(1)\fP, \fBgit\-bug\-commands(1)\fP, \fBgit\-bug\-comment(1)\fP, \fBgit\-bug\-label(1)\fP, \fBgit\-bug\-ls(1)\fP, \fBgit\-bug\-ls\-label(1)\fP, \fBgit\-bug\-pull(1)\fP, \fBgit\-bug\-push(1)\fP, \fBgit\-bug\-select(1)\fP, \fBgit\-bug\-show(1)\fP, \fBgit\-bug\-status(1)\fP, \fBgit\-bug\-termui(1)\fP, \fBgit\-bug\-title(1)\fP, \fBgit\-bug\-webui(1)\fP
diff --git a/doc/md/git-bug.md b/doc/md/git-bug.md
index af5386ff..3d0592c9 100644
--- a/doc/md/git-bug.md
+++ b/doc/md/git-bug.md
@@ -25,6 +25,7 @@ git-bug [flags]
* [git-bug comment](git-bug_comment.md) - Display or add comments
* [git-bug label](git-bug_label.md) - Display, add or remove labels
* [git-bug ls](git-bug_ls.md) - List bugs
+* [git-bug ls-label](git-bug_ls-label.md) - List valid labels
* [git-bug pull](git-bug_pull.md) - Pull bugs update from a git remote
* [git-bug push](git-bug_push.md) - Push bugs update to a git remote
* [git-bug select](git-bug_select.md) - Select a bug for implicit use in future commands
diff --git a/doc/md/git-bug_ls-label.md b/doc/md/git-bug_ls-label.md
new file mode 100644
index 00000000..f3b82f4f
--- /dev/null
+++ b/doc/md/git-bug_ls-label.md
@@ -0,0 +1,24 @@
+## git-bug ls-label
+
+List valid labels
+
+### Synopsis
+
+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.
+
+```
+git-bug ls-label [flags]
+```
+
+### Options
+
+```
+ -h, --help help for ls-label
+```
+
+### SEE ALSO
+
+* [git-bug](git-bug.md) - A bug tracker embedded in Git
+
diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug
index 9d8482c8..c78391dd 100644
--- a/misc/bash_completion/git-bug
+++ b/misc/bash_completion/git-bug
@@ -447,6 +447,26 @@ _git-bug_ls()
noun_aliases=()
}
+_git-bug_ls-label()
+{
+ last_command="git-bug_ls-label"
+
+ command_aliases=()
+
+ commands=()
+
+ flags=()
+ two_word_flags=()
+ local_nonpersistent_flags=()
+ flags_with_completion=()
+ flags_completion=()
+
+
+ must_have_one_flag=()
+ must_have_one_noun=()
+ noun_aliases=()
+}
+
_git-bug_pull()
{
last_command="git-bug_pull"
@@ -688,6 +708,7 @@ _git-bug_root_command()
commands+=("comment")
commands+=("label")
commands+=("ls")
+ commands+=("ls-label")
commands+=("pull")
commands+=("push")
commands+=("select")
diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug
index 4ad6663a..077fa181 100644
--- a/misc/zsh_completion/git-bug
+++ b/misc/zsh_completion/git-bug
@@ -8,7 +8,7 @@ case $state in
level1)
case $words[1] in
git-bug)
- _arguments '1: :(add commands comment label ls pull push select show status termui title webui)'
+ _arguments '1: :(add commands comment label ls ls-label pull push select show status termui title webui)'
;;
*)
_arguments '*: :_files'