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 https://github.com/MichaelMure/git-bug/issues/47

Change summary

commands/ls-id.go                  | 80 ++++++++++++++++++++++++++++++++
doc/man/git-bug-add.1              |  2 
doc/man/git-bug-bridge-configure.1 |  2 
doc/man/git-bug-bridge-pull.1      |  2 
doc/man/git-bug-bridge-rm.1        |  2 
doc/man/git-bug-bridge.1           |  2 
doc/man/git-bug-commands.1         |  2 
doc/man/git-bug-comment-add.1      |  2 
doc/man/git-bug-comment.1          |  2 
doc/man/git-bug-deselect.1         |  2 
doc/man/git-bug-label-add.1        |  2 
doc/man/git-bug-label-rm.1         |  2 
doc/man/git-bug-label.1            |  2 
doc/man/git-bug-ls-label.1         |  2 
doc/man/git-bug-ls.1               |  2 
doc/man/git-bug-pull.1             |  2 
doc/man/git-bug-push.1             |  2 
doc/man/git-bug-select.1           |  2 
doc/man/git-bug-show.1             |  2 
doc/man/git-bug-status-close.1     |  2 
doc/man/git-bug-status-open.1      |  2 
doc/man/git-bug-status.1           |  2 
doc/man/git-bug-termui.1           |  2 
doc/man/git-bug-title-edit.1       |  2 
doc/man/git-bug-title.1            |  2 
doc/man/git-bug-webui.1            |  2 
doc/man/git-bug.1                  |  4 
doc/md/git-bug.md                  |  1 
misc/bash_completion/git-bug       | 21 ++++++++
misc/zsh_completion/git-bug        |  2 
30 files changed, 130 insertions(+), 28 deletions(-)

Detailed changes

commands/ls-id.go 🔗

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

doc/man/git-bug-add.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-bridge-configure.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-bridge-pull.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-bridge-rm.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-bridge.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-commands.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-comment-add.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-comment.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-deselect.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-label-add.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-label-rm.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-label.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-ls-label.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-ls.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-pull.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-push.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-select.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-show.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-status-close.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-status-open.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-status.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-termui.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-title-edit.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-title.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug-webui.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" "" 
 .nh
 .ad l
 

doc/man/git-bug.1 🔗

@@ -1,4 +1,4 @@
-.TH "GIT-BUG" "1" "Dec 2018" "Generated from git-bug's source code" "" 
+.TH "GIT-BUG" "1" "Feb 2019" "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\-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\-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

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"
@@ -816,6 +836,7 @@ _git-bug_root_command()
     commands+=("deselect")
     commands+=("label")
     commands+=("ls")
+    commands+=("ls-id")
     commands+=("ls-label")
     commands+=("pull")
     commands+=("push")

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-label pull push select show status termui title webui)'
+        _arguments '1: :(add bridge commands comment deselect label ls ls-id ls-label pull push select show status termui title webui)'
       ;;
       *)
         _arguments '*: :_files'