From 76ac1787b8de8698b878d1837c5fa8f6fe6403fc Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Tue, 17 Jul 2018 19:28:37 +0200 Subject: add bug status + open/close commands --- commands/close.go | 39 +++++++++++++++++++++++++++++++++++++++ commands/command.go | 2 ++ commands/comment.go | 9 +++++---- commands/ls.go | 2 +- commands/open.go | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 commands/close.go create mode 100644 commands/open.go (limited to 'commands') diff --git a/commands/close.go b/commands/close.go new file mode 100644 index 00000000..6e668a50 --- /dev/null +++ b/commands/close.go @@ -0,0 +1,39 @@ +package commands + +import ( + "errors" + "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/bug/operations" + "github.com/MichaelMure/git-bug/repository" +) + +func runCloseBug(repo repository.Repo, args []string) error { + if len(args) > 1 { + return errors.New("Only closing one bug at a time is supported") + } + + if len(args) == 0 { + return errors.New("You must provide a bug id") + } + + prefix := args[0] + + b, err := bug.FindBug(repo, prefix) + if err != nil { + return err + } + + op := operations.NewSetStatusOp(bug.ClosedStatus) + + b.Append(op) + + err = b.Commit(repo) + + return err +} + +var closeCmd = &Command{ + Description: "Mark the bug as closed", + Usage: "", + RunMethod: runCloseBug, +} diff --git a/commands/command.go b/commands/command.go index cb231dce..111f9603 100644 --- a/commands/command.go +++ b/commands/command.go @@ -44,10 +44,12 @@ var CommandMap map[string]*Command // We use init() to avoid a cycle in the data initialization because of the "commands" command func init() { CommandMap = map[string]*Command{ + "close": closeCmd, "commands": commandsCmd, "comment": commentCmd, "ls": lsCmd, "new": newCmd, + "open": openCmd, "pull": pullCmd, "push": pushCmd, "webui": webUICmd, diff --git a/commands/comment.go b/commands/comment.go index f635139b..9815dac4 100644 --- a/commands/comment.go +++ b/commands/comment.go @@ -22,11 +22,12 @@ func runComment(repo repository.Repo, args []string) error { var err error - if len(args) == 0 { - return errors.New("No bug id provided") - } if len(args) > 1 { - return errors.New("Only accepting one bug id is supported") + return errors.New("Only one bug id is supported") + } + + if len(args) == 0 { + return errors.New("You must provide a bug id") } prefix := args[0] diff --git a/commands/ls.go b/commands/ls.go index 94755b2d..ac0bcfbb 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -22,7 +22,7 @@ func runLsBug(repo repository.Repo, args []string) error { snapshot := bug.Compile() - fmt.Printf("%s %s\t%s\n", bug.HumanId(), snapshot.Title, snapshot.Summary()) + fmt.Printf("%s %s\t%s\t%s\n", bug.HumanId(), snapshot.Status, snapshot.Title, snapshot.Summary()) } return nil diff --git a/commands/open.go b/commands/open.go new file mode 100644 index 00000000..91704da3 --- /dev/null +++ b/commands/open.go @@ -0,0 +1,39 @@ +package commands + +import ( + "errors" + "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/bug/operations" + "github.com/MichaelMure/git-bug/repository" +) + +func runOpenBug(repo repository.Repo, args []string) error { + if len(args) > 1 { + return errors.New("Only opening one bug at a time is supported") + } + + if len(args) == 0 { + return errors.New("You must provide a bug id") + } + + prefix := args[0] + + b, err := bug.FindBug(repo, prefix) + if err != nil { + return err + } + + op := operations.NewSetStatusOp(bug.OpenStatus) + + b.Append(op) + + err = b.Commit(repo) + + return err +} + +var openCmd = &Command{ + Description: "Mark the bug as open", + Usage: "", + RunMethod: runOpenBug, +} -- cgit