aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-17 19:28:37 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-17 19:28:37 +0200
commit76ac1787b8de8698b878d1837c5fa8f6fe6403fc (patch)
tree2261d605eb533bc5f037887a983da0039281c9f5 /commands
parent7b19b10e19e5dbbae79a47d3e4338b15b3e8d972 (diff)
downloadgit-bug-76ac1787b8de8698b878d1837c5fa8f6fe6403fc.tar.gz
add bug status + open/close commands
Diffstat (limited to 'commands')
-rw-r--r--commands/close.go39
-rw-r--r--commands/command.go2
-rw-r--r--commands/comment.go9
-rw-r--r--commands/ls.go2
-rw-r--r--commands/open.go39
5 files changed, 86 insertions, 5 deletions
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: "<id>",
+ 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: "<id>",
+ RunMethod: runOpenBug,
+}