aboutsummaryrefslogtreecommitdiffstats
path: root/commands/new.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-12 12:44:46 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-12 12:44:46 +0200
commitc498674718608a1171a4fcef6f26184df7d5fa7b (patch)
tree9cc53ea07b61d52b12cd5fa3367b25d04bebc150 /commands/new.go
parentd0443659123f912e9385e27efebe4b7da65aa2f6 (diff)
downloadgit-bug-c498674718608a1171a4fcef6f26184df7d5fa7b.tar.gz
add the new bug command with a very primitive bug datastructure
Diffstat (limited to 'commands/new.go')
-rw-r--r--commands/new.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/commands/new.go b/commands/new.go
new file mode 100644
index 00000000..0156477e
--- /dev/null
+++ b/commands/new.go
@@ -0,0 +1,75 @@
+package commands
+
+import (
+ "flag"
+ "fmt"
+ "github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/commands/input"
+ "github.com/MichaelMure/git-bug/repository"
+ "github.com/pkg/errors"
+)
+
+var newFlagSet = flag.NewFlagSet("new", flag.ExitOnError)
+
+var (
+ newMessageFile = newFlagSet.String("F", "", "Take the message from the given file. Use - to read the message from the standard input")
+ newMessage = newFlagSet.String("m", "", "Provide a message to describe the issue")
+)
+
+func newBug(repo repository.Repo, args []string) error {
+ newFlagSet.Parse(args)
+ args = newFlagSet.Args()
+
+ var err error
+
+ if len(args) == 0 {
+ return errors.New("No title provided")
+ }
+ if len(args) > 1 {
+ return errors.New("Only accepting one title is supported")
+ }
+
+ title := args[0]
+
+ if *newMessageFile != "" && *newMessage == "" {
+ *newMessage, err = input.FromFile(*newMessageFile)
+ if err != nil {
+ return err
+ }
+ }
+ if *newMessageFile == "" && *newMessage == "" {
+ *newMessage, err = input.LaunchEditor(repo, messageFilename)
+ if err != nil {
+ return err
+ }
+ }
+
+ // Note: this is very primitive for now
+ author, err := bug.GetUser(repo)
+ if err != nil {
+ return err
+ }
+
+ comment := bug.Comment{
+ Author: author,
+ Message: *newMessage,
+ }
+
+ bug := bug.Bug{
+ Title: title,
+ Comments: []bug.Comment{comment},
+ }
+
+ fmt.Println(bug)
+
+ return nil
+
+}
+
+var newCmd = &Command{
+ Usage: func(arg0 string) {
+ fmt.Printf("Usage: %s new <title> [<option>...]\n\nOptions:\n", arg0)
+ newFlagSet.PrintDefaults()
+ },
+ RunMethod: newBug,
+}