From 3c0c13bbbe934d0fa9476fa5c07bf04ea5a99b94 Mon Sep 17 00:00:00 2001 From: Sladyn Date: Thu, 14 Feb 2019 00:38:55 +0530 Subject: ls-id.go:Add ls-id [] 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 #47 --- commands/ls-id.go | 59 +++++++------------------------------------------------ 1 file changed, 7 insertions(+), 52 deletions(-) (limited to 'commands/ls-id.go') diff --git a/commands/ls-id.go b/commands/ls-id.go index 6e6da4c1..b9866828 100644 --- a/commands/ls-id.go +++ b/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{ -- cgit