blob: 737632c3852e9a34b1eb26975f9e529223a35b71 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package commands
import (
"fmt"
"github.com/MichaelMure/git-bug/webui"
"github.com/gorilla/mux"
"github.com/phayes/freeport"
"github.com/skratchdot/open-golang/open"
"github.com/spf13/cobra"
"log"
"net/http"
)
func runWebUI(cmd *cobra.Command, 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 = &cobra.Command{
Use: "webui",
Short: "Launch the web UI",
RunE: runWebUI,
}
func init() {
rootCmd.AddCommand(webUICmd)
}
|