diff options
author | Sladyn <gunnerforlife00@gmail.com> | 2019-02-08 23:55:19 +0530 |
---|---|---|
committer | Sladyn <gunnerforlife00@gmail.com> | 2019-02-14 00:32:40 +0530 |
commit | f70f38c8ee44338e803ba6bb306c13fe1c7f347a (patch) | |
tree | a36d96b2b01071d3d850f3a04af5f601ba6d0c77 | |
parent | bb0066344a12d6ba58ab4dfc420b4fe5308e0a71 (diff) | |
download | git-bug-f70f38c8ee44338e803ba6bb306c13fe1c7f347a.tar.gz |
ls-id.go: Add ls-id [<prefix>] command
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
30 files changed, 130 insertions, 28 deletions
diff --git a/commands/ls-id.go b/commands/ls-id.go new file mode 100644 index 00000000..6e6da4c1 --- /dev/null +++ b/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) +} diff --git a/doc/man/git-bug-add.1 b/doc/man/git-bug-add.1 index 4ad632a9..dffec904 100644 --- a/doc/man/git-bug-add.1 +++ b/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 diff --git a/doc/man/git-bug-bridge-configure.1 b/doc/man/git-bug-bridge-configure.1 index 62ff07e6..e84258f7 100644 --- a/doc/man/git-bug-bridge-configure.1 +++ b/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 diff --git a/doc/man/git-bug-bridge-pull.1 b/doc/man/git-bug-bridge-pull.1 index 26bd210e..c9f117c7 100644 --- a/doc/man/git-bug-bridge-pull.1 +++ b/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 diff --git a/doc/man/git-bug-bridge-rm.1 b/doc/man/git-bug-bridge-rm.1 index 2d28dea6..7f538acc 100644 --- a/doc/man/git-bug-bridge-rm.1 +++ b/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 diff --git a/doc/man/git-bug-bridge.1 b/doc/man/git-bug-bridge.1 index b182c658..4eeb627a 100644 --- a/doc/man/git-bug-bridge.1 +++ b/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 diff --git a/doc/man/git-bug-commands.1 b/doc/man/git-bug-commands.1 index 0f460387..d959b2c9 100644 --- a/doc/man/git-bug-commands.1 +++ b/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 diff --git a/doc/man/git-bug-comment-add.1 b/doc/man/git-bug-comment-add.1 index 6095a87f..8a7ce4fa 100644 --- a/doc/man/git-bug-comment-add.1 +++ b/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 diff --git a/doc/man/git-bug-comment.1 b/doc/man/git-bug-comment.1 index 0cb834be..4b5300f4 100644 --- a/doc/man/git-bug-comment.1 +++ b/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 diff --git a/doc/man/git-bug-deselect.1 b/doc/man/git-bug-deselect.1 index 602365d6..35f45501 100644 --- a/doc/man/git-bug-deselect.1 +++ b/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 diff --git a/doc/man/git-bug-label-add.1 b/doc/man/git-bug-label-add.1 index 10798908..5cbdbb6a 100644 --- a/doc/man/git-bug-label-add.1 +++ b/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 diff --git a/doc/man/git-bug-label-rm.1 b/doc/man/git-bug-label-rm.1 index fc33c3d7..fb7efdc9 100644 --- a/doc/man/git-bug-label-rm.1 +++ b/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 diff --git a/doc/man/git-bug-label.1 b/doc/man/git-bug-label.1 index 68ab6726..d4cde473 100644 --- a/doc/man/git-bug-label.1 +++ b/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 diff --git a/doc/man/git-bug-ls-label.1 b/doc/man/git-bug-ls-label.1 index 25eb7074..1b69b305 100644 --- a/doc/man/git-bug-ls-label.1 +++ b/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 diff --git a/doc/man/git-bug-ls.1 b/doc/man/git-bug-ls.1 index 8a96ca77..e9cdb4c8 100644 --- a/doc/man/git-bug-ls.1 +++ b/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 diff --git a/doc/man/git-bug-pull.1 b/doc/man/git-bug-pull.1 index 5614534d..315ce01a 100644 --- a/doc/man/git-bug-pull.1 +++ b/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 diff --git a/doc/man/git-bug-push.1 b/doc/man/git-bug-push.1 index 4779318b..0466e0ef 100644 --- a/doc/man/git-bug-push.1 +++ b/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 diff --git a/doc/man/git-bug-select.1 b/doc/man/git-bug-select.1 index f0730194..9324a873 100644 --- a/doc/man/git-bug-select.1 +++ b/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 diff --git a/doc/man/git-bug-show.1 b/doc/man/git-bug-show.1 index 05f856e9..443b75ec 100644 --- a/doc/man/git-bug-show.1 +++ b/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 diff --git a/doc/man/git-bug-status-close.1 b/doc/man/git-bug-status-close.1 index 71e9cdfe..9552d037 100644 --- a/doc/man/git-bug-status-close.1 +++ b/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 diff --git a/doc/man/git-bug-status-open.1 b/doc/man/git-bug-status-open.1 index 0e7fe8ae..9f7b69cf 100644 --- a/doc/man/git-bug-status-open.1 +++ b/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 diff --git a/doc/man/git-bug-status.1 b/doc/man/git-bug-status.1 index 0f2e1b40..c31e542d 100644 --- a/doc/man/git-bug-status.1 +++ b/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 diff --git a/doc/man/git-bug-termui.1 b/doc/man/git-bug-termui.1 index 9f66a00f..d395ab06 100644 --- a/doc/man/git-bug-termui.1 +++ b/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 diff --git a/doc/man/git-bug-title-edit.1 b/doc/man/git-bug-title-edit.1 index 4012fcbb..ab33c4ae 100644 --- a/doc/man/git-bug-title-edit.1 +++ b/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 diff --git a/doc/man/git-bug-title.1 b/doc/man/git-bug-title.1 index 6888fe8e..5dc58465 100644 --- a/doc/man/git-bug-title.1 +++ b/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 diff --git a/doc/man/git-bug-webui.1 b/doc/man/git-bug-webui.1 index 0310b130..5ca9e4e9 100644 --- a/doc/man/git-bug-webui.1 +++ b/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 diff --git a/doc/man/git-bug.1 b/doc/man/git-bug.1 index 183d60d8..6a5e2901 100644 --- a/doc/man/git-bug.1 +++ b/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 diff --git a/doc/md/git-bug.md b/doc/md/git-bug.md index 2cc44eff..4acec84c 100644 --- a/doc/md/git-bug.md +++ b/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 diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index d6c28214..3870e3a0 100644 --- a/misc/bash_completion/git-bug +++ b/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") diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug index 2deae548..c8cc7c2c 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 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' |