1package commands
2
3import (
4 "fmt"
5 "strings"
6
7 "github.com/MichaelMure/git-bug/cache"
8 "github.com/spf13/cobra"
9)
10
11func runLsID(cmd *cobra.Command, args []string) error {
12
13 backend, err := cache.NewRepoCache(repo)
14 if err != nil {
15 return err
16 }
17 defer backend.Close()
18
19 var prefix = ""
20 if len(args) != 0 {
21 prefix = args[0]
22 }
23
24 for _, id := range backend.AllBugsIds() {
25 if prefix == "" || strings.HasPrefix(id, prefix) {
26 fmt.Println(id)
27 }
28 }
29
30 return nil
31}
32
33var listBugIDCmd = &cobra.Command{
34 Use: "ls-id [<prefix>]",
35 Short: "List Bug Id",
36 PreRunE: loadRepo,
37 RunE: runLsID,
38}
39
40func init() {
41 RootCmd.AddCommand(listBugIDCmd)
42}