ls-id.go:Add ls-id [<prefix>] command

Sladyn created

This file adds the ls-id command which returns
the bug id matching the prefix the user enters.
If no prefix entered it lists all the BugId's

Closes #47

Change summary

commands/ls-id.go           | 59 ++++----------------------------------
doc/man/git-bug.1           |  4 +-
misc/zsh_completion/git-bug |  2 
3 files changed, 10 insertions(+), 55 deletions(-)

Detailed changes

commands/ls-id.go 🔗

@@ -4,68 +4,23 @@ import (
 	"fmt"
 	"strings"
 
-	"github.com/MichaelMure/git-bug/bug"
+	"github.com/MichaelMure/git-bug/cache"
 	"github.com/spf13/cobra"
 )
 
 func runLsID(cmd *cobra.Command, args []string) error {
 
-	if len(args) < 1 {
-		_, err := ListAllID()
+	var backend *cache.RepoCache
 
-		if err != nil {
-			return err
-		}
-
-		return nil
-	}
-	answer, err := ListID(args[0])
-
-	if err != nil {
-		return err
-	}
-
-	if answer == "" {
-		fmt.Printf("No matching bug Id with prefix %s\n", args[0])
-	} else {
-		fmt.Println(answer)
-	}
-
-	return nil
-}
-
-//ListID lists the local bug id after taking the prefix as input
-func ListID(prefix string) (string, error) {
-
-	IDlist, err := bug.ListLocalIds(repo)
+	prefix := args[0]
 
-	if err != nil {
-		return "", err
-	}
-
-	for _, id := range IDlist {
-		if strings.HasPrefix(id, prefix) {
-			return id, nil
+	for _, id := range backend.AllBugsIds() {
+		if prefix == "" || strings.HasPrefix(id, prefix) {
+			fmt.Println(id)
 		}
 	}
 
-	return "", nil
-
-}
-
-//ListAllID lists all the local bug id
-func ListAllID() (string, error) {
-
-	IDlist, err := bug.ListLocalIds(repo)
-	if err != nil {
-		return "", err
-	}
-
-	for _, id := range IDlist {
-		fmt.Println(id)
-	}
-
-	return "", nil
+	return nil
 }
 
 var listBugIDCmd = &cobra.Command{

doc/man/git-bug.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 
@@ -31,4 +31,4 @@ the same git remote your are already using to collaborate with other peoples.
 
 .SH SEE ALSO
 .PP
-\fBgit\-bug\-add(1)\fP, \fBgit\-bug\-bridge(1)\fP, \fBgit\-bug\-commands(1)\fP, \fBgit\-bug\-comment(1)\fP, \fBgit\-bug\-deselect(1)\fP, \fBgit\-bug\-label(1)\fP, \fBgit\-bug\-ls(1)\fP, \fBgit\-bug\-ls\-id(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
+\fBgit\-bug\-add(1)\fP, \fBgit\-bug\-bridge(1)\fP, \fBgit\-bug\-commands(1)\fP, \fBgit\-bug\-comment(1)\fP, \fBgit\-bug\-deselect(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

misc/zsh_completion/git-bug 🔗

@@ -8,7 +8,7 @@ case $state in
   level1)
     case $words[1] in
       git-bug)
-        _arguments '1: :(add bridge commands comment deselect label ls ls-id ls-label pull push select show status termui title webui)'
+        _arguments '1: :(add bridge commands comment deselect label ls ls-label pull push select show status termui title webui)'
       ;;
       *)
         _arguments '*: :_files'