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 /commands/ls-id.go | |
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
Diffstat (limited to 'commands/ls-id.go')
-rw-r--r-- | commands/ls-id.go | 80 |
1 files changed, 80 insertions, 0 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) +} |