From 519c5acdd88fc349e3972862887a6e919eb5e7c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sat, 14 Jul 2018 22:19:05 +0200 Subject: [PATCH] add a primitive "list" command --- commands/commands.go | 1 + commands/list.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 commands/list.go diff --git a/commands/commands.go b/commands/commands.go index 343d1c7199712495d0195953aa1542745dd7d9c5..f4e9aef9fd50007bfe442c4f76e2992196e88af9 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -23,6 +23,7 @@ func (cmd *Command) Run(repo repository.Repo, args []string) error { // CommandMap defines all of the available (sub)commands. var CommandMap = map[string]*Command{ + "list": listCmd, "new": newCmd, "pull": pullCmd, "push": pushCmd, diff --git a/commands/list.go b/commands/list.go new file mode 100644 index 0000000000000000000000000000000000000000..87c417cf9bd7a2b65e57703defce84c26500bdad --- /dev/null +++ b/commands/list.go @@ -0,0 +1,36 @@ +package commands + +import ( + "fmt" + b "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/repository" +) + +func RunListBug(repo repository.Repo, args []string) error { + refs, err := repo.ListRefs(b.BugsRefPattern) + + if err != nil { + return err + } + + for _, ref := range refs { + bug, err := b.ReadBug(repo, ref) + + if err != nil { + return err + } + + snapshot := bug.Compile() + + fmt.Printf("%s %s\n", bug.HumanId(), snapshot.Title) + } + + return nil +} + +var listCmd = &Command{ + Usage: func(arg0 string) { + fmt.Printf("Usage: %s\n", arg0) + }, + RunMethod: RunListBug, +}