2019-02-08 21:25:19 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2019-08-12 17:12:14 +03:00
|
|
|
"github.com/spf13/cobra"
|
2019-02-08 21:25:19 +03:00
|
|
|
|
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
|
|
|
)
|
|
|
|
|
2020-06-28 19:26:29 +03:00
|
|
|
func newLsIdCommand() *cobra.Command {
|
|
|
|
env := newEnv()
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "ls-id [<prefix>]",
|
|
|
|
Short: "List bug identifiers.",
|
|
|
|
PreRunE: loadRepo(env),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return runLsId(env, args)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
2019-02-08 21:25:19 +03:00
|
|
|
|
2020-06-28 19:26:29 +03:00
|
|
|
func runLsId(env *Env, args []string) error {
|
|
|
|
backend, err := cache.NewRepoCache(env.repo)
|
2019-03-04 21:33:38 +03:00
|
|
|
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() {
|
2019-08-12 17:12:14 +03:00
|
|
|
if prefix == "" || id.HasPrefix(prefix) {
|
2020-06-28 19:26:29 +03:00
|
|
|
env.out.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
|
|
|
}
|