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