2018-07-16 23:25:50 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/MichaelMure/git-bug/webui"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/phayes/freeport"
|
|
|
|
"github.com/skratchdot/open-golang/open"
|
2018-07-19 13:30:25 +03:00
|
|
|
"github.com/spf13/cobra"
|
2018-07-16 23:25:50 +03:00
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
func runWebUI(cmd *cobra.Command, args []string) error {
|
2018-07-16 23:25:50 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
var webUICmd = &cobra.Command{
|
|
|
|
Use: "webui",
|
|
|
|
Short: "Launch the web UI",
|
|
|
|
RunE: runWebUI,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(webUICmd)
|
2018-07-16 23:25:50 +03:00
|
|
|
}
|