diff options
-rw-r--r-- | commands/commands.go | 9 | ||||
-rw-r--r-- | commands/comment.go | 73 | ||||
-rw-r--r-- | commands/ls.go | 6 | ||||
-rw-r--r-- | commands/new.go | 5 | ||||
-rw-r--r-- | commands/pull.go | 4 | ||||
-rw-r--r-- | commands/push.go | 4 |
6 files changed, 87 insertions, 14 deletions
diff --git a/commands/commands.go b/commands/commands.go index 7c4e3ab9..faca02ab 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -23,8 +23,9 @@ func (cmd *Command) Run(repo repository.Repo, args []string) error { // CommandMap defines all of the available (sub)commands. var CommandMap = map[string]*Command{ - "ls": lsCmd, - "new": newCmd, - "pull": pullCmd, - "push": pushCmd, + "comment": commentCmd, + "ls": lsCmd, + "new": newCmd, + "pull": pullCmd, + "push": pushCmd, } diff --git a/commands/comment.go b/commands/comment.go new file mode 100644 index 00000000..27908793 --- /dev/null +++ b/commands/comment.go @@ -0,0 +1,73 @@ +package commands + +import ( + "errors" + "flag" + "fmt" + "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/bug/operations" + "github.com/MichaelMure/git-bug/commands/input" + "github.com/MichaelMure/git-bug/repository" +) + +var commentFlagSet = flag.NewFlagSet("comment", flag.ExitOnError) + +var ( + commentMessageFile = commentFlagSet.String("F", "", "Take the message from the given file. Use - to read the message from the standard input") + commentMessage = commentFlagSet.String("m", "", "Provide the new message from the command line") +) + +func runComment(repo repository.Repo, args []string) error { + commentFlagSet.Parse(args) + args = commentFlagSet.Args() + + 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") + } + + prefix := args[0] + + if *commentMessageFile != "" && *commentMessage == "" { + *commentMessage, err = input.FromFile(*commentMessageFile) + if err != nil { + return err + } + } + if *commentMessageFile == "" && *commentMessage == "" { + *commentMessage, err = input.LaunchEditor(repo, messageFilename) + if err != nil { + return err + } + } + + author, err := bug.GetUser(repo) + if err != nil { + return err + } + + bug, err := bug.FindBug(repo, prefix) + if err != nil { + return err + } + + addCommentOp := operations.NewAddCommentOp(author, *commentMessage) + + bug.Append(addCommentOp) + + err = bug.Commit(repo) + + return err +} + +var commentCmd = &Command{ + Usage: func(arg0 string) { + fmt.Printf("Usage: %s comment <id> [<option>...]\n\nOptions:\n", arg0) + commentFlagSet.PrintDefaults() + }, + RunMethod: runComment, +} diff --git a/commands/ls.go b/commands/ls.go index 631afb5e..1e001ddb 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -6,7 +6,7 @@ import ( "github.com/MichaelMure/git-bug/repository" ) -func RunLsBug(repo repository.Repo, args []string) error { +func runLsBug(repo repository.Repo, args []string) error { refs, err := repo.ListRefs(b.BugsRefPattern) if err != nil { @@ -30,7 +30,7 @@ func RunLsBug(repo repository.Repo, args []string) error { var lsCmd = &Command{ Usage: func(arg0 string) { - fmt.Printf("Usage: %s\n", arg0) + fmt.Printf("Usage: %s ls\n", arg0) }, - RunMethod: RunLsBug, + RunMethod: runLsBug, } diff --git a/commands/new.go b/commands/new.go index d2e1ed59..2db95291 100644 --- a/commands/new.go +++ b/commands/new.go @@ -17,7 +17,7 @@ var ( newMessage = newFlagSet.String("m", "", "Provide a message to describe the issue") ) -func RunNewBug(repo repository.Repo, args []string) error { +func runNewBug(repo repository.Repo, args []string) error { newFlagSet.Parse(args) args = newFlagSet.Args() @@ -45,7 +45,6 @@ func RunNewBug(repo repository.Repo, args []string) error { } } - // Note: this is very primitive for now author, err := bug.GetUser(repo) if err != nil { return err @@ -71,5 +70,5 @@ var newCmd = &Command{ fmt.Printf("Usage: %s new <title> [<option>...]\n\nOptions:\n", arg0) newFlagSet.PrintDefaults() }, - RunMethod: RunNewBug, + RunMethod: runNewBug, } diff --git a/commands/pull.go b/commands/pull.go index 105fce9c..b408c285 100644 --- a/commands/pull.go +++ b/commands/pull.go @@ -7,7 +7,7 @@ import ( "github.com/MichaelMure/git-bug/repository" ) -func pull(repo repository.Repo, args []string) error { +func runPull(repo repository.Repo, args []string) error { if len(args) > 1 { return errors.New("Only pulling from one remote at a time is supported") } @@ -28,5 +28,5 @@ var pullCmd = &Command{ Usage: func(arg0 string) { fmt.Printf("Usage: %s pull [<remote>]\n", arg0) }, - RunMethod: pull, + RunMethod: runPull, } diff --git a/commands/push.go b/commands/push.go index 54a657b9..416a61a1 100644 --- a/commands/push.go +++ b/commands/push.go @@ -7,7 +7,7 @@ import ( "github.com/MichaelMure/git-bug/repository" ) -func push(repo repository.Repo, args []string) error { +func runPush(repo repository.Repo, args []string) error { if len(args) > 1 { return errors.New("Only pushing to one remote at a time is supported") } @@ -28,5 +28,5 @@ var pushCmd = &Command{ Usage: func(arg0 string) { fmt.Printf("Usage: %s push [<remote>]\n", arg0) }, - RunMethod: push, + RunMethod: runPush, } |