2018-07-14 23:19:05 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-08-13 19:32:11 +03:00
|
|
|
|
2018-07-23 01:04:46 +03:00
|
|
|
"github.com/MichaelMure/git-bug/bug"
|
2018-09-02 16:46:43 +03:00
|
|
|
"github.com/MichaelMure/git-bug/cache"
|
2018-07-17 21:23:14 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util"
|
2018-07-19 13:30:25 +03:00
|
|
|
"github.com/spf13/cobra"
|
2018-07-14 23:19:05 +03:00
|
|
|
)
|
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
func runLsBug(cmd *cobra.Command, args []string) error {
|
2018-09-02 16:46:43 +03:00
|
|
|
backend, err := cache.NewRepoCache(repo)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-09-04 19:18:24 +03:00
|
|
|
defer backend.Close()
|
2018-08-31 14:18:03 +03:00
|
|
|
|
2018-09-09 21:22:46 +03:00
|
|
|
var query *cache.Query
|
|
|
|
if len(args) >= 1 {
|
|
|
|
query, err = cache.ParseQuery(args[0])
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
allIds := backend.QueryBugs(query)
|
2018-07-14 23:19:05 +03:00
|
|
|
|
2018-09-02 16:46:43 +03:00
|
|
|
for _, id := range allIds {
|
|
|
|
b, err := backend.ResolveBug(id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-07-14 23:19:05 +03:00
|
|
|
}
|
|
|
|
|
2018-09-02 16:46:43 +03:00
|
|
|
snapshot := b.Snapshot()
|
2018-07-14 23:19:05 +03:00
|
|
|
|
2018-07-23 01:04:46 +03:00
|
|
|
var author bug.Person
|
2018-07-17 21:23:14 +03:00
|
|
|
|
|
|
|
if len(snapshot.Comments) > 0 {
|
|
|
|
create := snapshot.Comments[0]
|
|
|
|
author = create.Author
|
|
|
|
}
|
|
|
|
|
|
|
|
// truncate + pad if needed
|
|
|
|
titleFmt := fmt.Sprintf("%-50.50s", snapshot.Title)
|
|
|
|
authorFmt := fmt.Sprintf("%-15.15s", author.Name)
|
|
|
|
|
|
|
|
fmt.Printf("%s %s\t%s\t%s\t%s\n",
|
2018-09-02 16:46:43 +03:00
|
|
|
util.Cyan(b.HumanId()),
|
2018-07-17 21:23:14 +03:00
|
|
|
util.Yellow(snapshot.Status),
|
|
|
|
titleFmt,
|
|
|
|
util.Magenta(authorFmt),
|
|
|
|
snapshot.Summary(),
|
|
|
|
)
|
2018-07-14 23:19:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
var lsCmd = &cobra.Command{
|
2018-09-09 21:22:46 +03:00
|
|
|
Use: "ls <query>",
|
2018-07-19 13:30:25 +03:00
|
|
|
Short: "Display a summary of all bugs",
|
|
|
|
RunE: runLsBug,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2018-07-20 16:46:14 +03:00
|
|
|
RootCmd.AddCommand(lsCmd)
|
2018-07-14 23:19:05 +03:00
|
|
|
}
|