aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-16 22:25:50 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-16 22:25:50 +0200
commitead4511250deb877e1867c2e38cbee9c27deb299 (patch)
tree09572e68634c7241eff7cb65bf94c02a6aac9a50 /commands
parentd659d74131996cea06e39f90114e21b36e61f6fc (diff)
downloadgit-bug-ead4511250deb877e1867c2e38cbee9c27deb299.tar.gz
add the infrastructure for an embedded web UI + command
Diffstat (limited to 'commands')
-rw-r--r--commands/command.go1
-rw-r--r--commands/webui.go37
2 files changed, 38 insertions, 0 deletions
diff --git a/commands/command.go b/commands/command.go
index 30298d3f..cb231dce 100644
--- a/commands/command.go
+++ b/commands/command.go
@@ -50,5 +50,6 @@ func init() {
"new": newCmd,
"pull": pullCmd,
"push": pushCmd,
+ "webui": webUICmd,
}
}
diff --git a/commands/webui.go b/commands/webui.go
new file mode 100644
index 00000000..df18d3b9
--- /dev/null
+++ b/commands/webui.go
@@ -0,0 +1,37 @@
+package commands
+
+import (
+ "fmt"
+ "github.com/MichaelMure/git-bug/repository"
+ "github.com/MichaelMure/git-bug/webui"
+ "github.com/gorilla/mux"
+ "github.com/phayes/freeport"
+ "github.com/skratchdot/open-golang/open"
+ "log"
+ "net/http"
+)
+
+func runWebUI(repo repository.Repo, args []string) error {
+ port, err := freeport.GetFreePort()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ addr := fmt.Sprintf("127.0.0.1:%d", port)
+
+ router := mux.NewRouter()
+ router.PathPrefix("/").Handler(http.FileServer(webui.WebUIAssets))
+
+ open.Run(fmt.Sprintf("http://%s", addr))
+
+ log.Fatal(http.ListenAndServe(addr, router))
+
+ return nil
+}
+
+var webUICmd = &Command{
+ Description: "Launch the web UI",
+ Usage: "",
+ flagSet: nil,
+ RunMethod: runWebUI,
+}