Merge pull request #97 from sladyn98/ls_id_branch

Michael Muré created

A command to list matching bug id from a prefix

Change summary

commands/ls-id.go            | 35 +++++++++++++++++++++++++++++++++++
doc/md/git-bug.md            |  1 +
misc/bash_completion/git-bug | 21 +++++++++++++++++++++
3 files changed, 57 insertions(+)

Detailed changes

commands/ls-id.go 🔗

@@ -0,0 +1,35 @@
+package commands
+
+import (
+	"fmt"
+	"strings"
+
+	"github.com/MichaelMure/git-bug/cache"
+	"github.com/spf13/cobra"
+)
+
+func runLsID(cmd *cobra.Command, args []string) error {
+
+	var backend *cache.RepoCache
+
+	prefix := args[0]
+
+	for _, id := range backend.AllBugsIds() {
+		if prefix == "" || strings.HasPrefix(id, prefix) {
+			fmt.Println(id)
+		}
+	}
+
+	return nil
+}
+
+var listBugIDCmd = &cobra.Command{
+	Use:     "ls-id [<prefix>]",
+	Short:   "List Bug Id",
+	PreRunE: loadRepo,
+	RunE:    runLsID,
+}
+
+func init() {
+	RootCmd.AddCommand(listBugIDCmd)
+}

doc/md/git-bug.md 🔗

@@ -31,6 +31,7 @@ git-bug [flags]
 * [git-bug deselect](git-bug_deselect.md)	 - Clear the implicitly selected bug
 * [git-bug label](git-bug_label.md)	 - Display, add or remove labels
 * [git-bug ls](git-bug_ls.md)	 - List bugs
+* [git-bug ls-id](git-bug_ls-id.md)	 - List Bug Id
 * [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

misc/bash_completion/git-bug 🔗

@@ -550,6 +550,26 @@ _git-bug_ls()
     noun_aliases=()
 }
 
+_git-bug_ls-id()
+{
+    last_command="git-bug_ls-id"
+
+    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_ls-label()
 {
     last_command="git-bug_ls-label"
@@ -845,6 +865,7 @@ _git-bug_root_command()
     commands+=("deselect")
     commands+=("label")
     commands+=("ls")
+    commands+=("ls-id")
     commands+=("ls-label")
     commands+=("pull")
     commands+=("push")