aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-12 09:55:13 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-12 09:55:13 +0200
commitd0443659123f912e9385e27efebe4b7da65aa2f6 (patch)
tree090a36d2618ecff259cbcabd501d33d460d1cd7a /commands
parenta85730cf5287d40a1e32d3a671ba2296c73387cb (diff)
downloadgit-bug-d0443659123f912e9385e27efebe4b7da65aa2f6.tar.gz
more experiment
Diffstat (limited to 'commands')
-rw-r--r--commands/commands.go40
-rw-r--r--commands/pull.go33
-rw-r--r--commands/push.go33
3 files changed, 106 insertions, 0 deletions
diff --git a/commands/commands.go b/commands/commands.go
new file mode 100644
index 00000000..4f892fdd
--- /dev/null
+++ b/commands/commands.go
@@ -0,0 +1,40 @@
+// Package commands contains the assorted sub commands supported by the git-bug tool.
+package commands
+
+import (
+ "github.com/MichaelMure/git-bug/repository"
+)
+
+const bugsRefPattern = "refs/bugs/*"
+
+// Command represents the definition of a single command.
+type Command struct {
+ Usage func(string)
+ RunMethod func(repository.Repo, []string) error
+}
+
+// Run executes a command, given its arguments.
+//
+// The args parameter is all of the command line args that followed the
+// subcommand.
+func (cmd *Command) Run(repo repository.Repo, args []string) error {
+ return cmd.RunMethod(repo, args)
+}
+
+// CommandMap defines all of the available (sub)commands.
+var CommandMap = map[string]*Command{
+ "pull": pullCmd,
+ "push": pushCmd,
+
+ /*"abandon": abandonCmd,
+ "accept": acceptCmd,
+ "comment": commentCmd,
+ "list": listCmd,
+ "pull": pullCmd,
+ "push": pushCmd,
+ "rebase": rebaseCmd,
+ "reject": rejectCmd,
+ "request": requestCmd,
+ "show": showCmd,
+ "submit": submitCmd,*/
+}
diff --git a/commands/pull.go b/commands/pull.go
new file mode 100644
index 00000000..0f6080d4
--- /dev/null
+++ b/commands/pull.go
@@ -0,0 +1,33 @@
+package commands
+
+import (
+ "fmt"
+ "github.com/MichaelMure/git-bug/repository"
+ "errors"
+)
+
+func pull(repo repository.Repo, args []string) error {
+ if len(args) > 1 {
+ return errors.New("only pulling from one remote at a time is supported")
+ }
+
+ remote := "origin"
+ if len(args) == 1 {
+ remote = args[0]
+ }
+
+ if err := repo.PullRefs(remote, bugsRefPattern); err != nil {
+ return err
+ }
+ return nil
+}
+
+// showCmd defines the "push" subcommand.
+var pullCmd = &Command{
+ Usage: func(arg0 string) {
+ fmt.Printf("Usage: %s pull [<remote>]\n", arg0)
+ },
+ RunMethod: func(repo repository.Repo, args []string) error {
+ return pull(repo, args)
+ },
+} \ No newline at end of file
diff --git a/commands/push.go b/commands/push.go
new file mode 100644
index 00000000..4465f561
--- /dev/null
+++ b/commands/push.go
@@ -0,0 +1,33 @@
+package commands
+
+import (
+ "fmt"
+ "github.com/MichaelMure/git-bug/repository"
+ "errors"
+)
+
+func push(repo repository.Repo, args []string) error {
+ if len(args) > 1 {
+ return errors.New("only pushing to one remote at a time is supported")
+ }
+
+ remote := "origin"
+ if len(args) == 1 {
+ remote = args[0]
+ }
+
+ if err := repo.PushRefs(remote, bugsRefPattern); err != nil {
+ return err
+ }
+ return nil
+}
+
+// showCmd defines the "push" subcommand.
+var pushCmd = &Command{
+ Usage: func(arg0 string) {
+ fmt.Printf("Usage: %s push [<remote>]\n", arg0)
+ },
+ RunMethod: func(repo repository.Repo, args []string) error {
+ return push(repo, args)
+ },
+} \ No newline at end of file