2019-02-08 21:25:19 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2019-02-13 22:08:55 +03:00
|
|
|
"github.com/MichaelMure/git-bug/cache"
|
2019-03-06 14:55:32 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util/interrupt"
|
2019-02-08 21:25:19 +03:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func runLsID(cmd *cobra.Command, args []string) error {
|
|
|
|
|
2019-03-04 21:33:38 +03:00
|
|
|
backend, err := cache.NewRepoCache(repo)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer backend.Close()
|
2019-03-06 14:55:32 +03:00
|
|
|
interrupt.RegisterCleaner(backend.Close)
|
2019-02-08 21:25:19 +03:00
|
|
|
|
2019-03-05 15:20:58 +03:00
|
|
|
var prefix = ""
|
2019-03-04 21:33:38 +03:00
|
|
|
if len(args) != 0 {
|
|
|
|
prefix = args[0]
|
|
|
|
}
|
2019-02-08 21:25:19 +03:00
|
|
|
|
2019-02-13 22:08:55 +03:00
|
|
|
for _, id := range backend.AllBugsIds() {
|
|
|
|
if prefix == "" || strings.HasPrefix(id, prefix) {
|
|
|
|
fmt.Println(id)
|
2019-02-08 21:25:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 22:08:55 +03:00
|
|
|
return nil
|
2019-02-08 21:25:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var listBugIDCmd = &cobra.Command{
|
|
|
|
Use: "ls-id [<prefix>]",
|
2019-05-04 20:54:12 +03:00
|
|
|
Short: "List bug identifiers.",
|
2019-02-08 21:25:19 +03:00
|
|
|
PreRunE: loadRepo,
|
|
|
|
RunE: runLsID,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RootCmd.AddCommand(listBugIDCmd)
|
|
|
|
}
|