aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-08-23 17:16:17 +0200
committerGitHub <noreply@github.com>2022-08-23 17:16:17 +0200
commit5238f29076f358f4266c0e77cc5322537713f3c0 (patch)
tree17dc3df82229eea5c3500e2bd8448060dc1ae849 /commands
parent5a70e8b3a2e0fe3d1a1dcd4c24bb6bf64633cb7f (diff)
parent8d11e620a3d663cf21a62910d0f3961a8aff4be1 (diff)
downloadgit-bug-5238f29076f358f4266c0e77cc5322537713f3c0.tar.gz
Merge pull request #859 from MichaelMure/webui-debug
webui: add a flag to log handling errors
Diffstat (limited to 'commands')
-rw-r--r--commands/webui.go26
1 files changed, 17 insertions, 9 deletions
diff --git a/commands/webui.go b/commands/webui.go
index 406485c3..758a153b 100644
--- a/commands/webui.go
+++ b/commands/webui.go
@@ -3,6 +3,7 @@ package commands
import (
"context"
"fmt"
+ "io"
"log"
"net"
"net/http"
@@ -30,12 +31,13 @@ import (
const webUIOpenConfigKey = "git-bug.webui.open"
type webUIOptions struct {
- host string
- port int
- open bool
- noOpen bool
- readOnly bool
- query string
+ host string
+ port int
+ open bool
+ noOpen bool
+ readOnly bool
+ logErrors bool
+ query string
}
func newWebUICommand() *cobra.Command {
@@ -52,7 +54,7 @@ Available git config:
`,
PreRunE: loadRepo(env),
RunE: func(cmd *cobra.Command, args []string) error {
- return runWebUI(env, options, args)
+ return runWebUI(env, options)
},
}
@@ -64,12 +66,13 @@ Available git config:
flags.BoolVar(&options.noOpen, "no-open", false, "Prevent the automatic opening of the web UI in the default browser")
flags.IntVarP(&options.port, "port", "p", 0, "Port to listen to (default to random available port)")
flags.BoolVar(&options.readOnly, "read-only", false, "Whether to run the web UI in read-only mode")
+ flags.BoolVar(&options.logErrors, "log-errors", false, "Whether to log errors")
flags.StringVarP(&options.query, "query", "q", "", "The query to open in the web UI bug list")
return cmd
}
-func runWebUI(env *Env, opts webUIOptions, args []string) error {
+func runWebUI(env *Env, opts webUIOptions) error {
if opts.port == 0 {
var err error
opts.port, err = freeport.GetFreePort()
@@ -106,7 +109,12 @@ func runWebUI(env *Env, opts webUIOptions, args []string) error {
return err
}
- graphqlHandler := graphql.NewHandler(mrc)
+ var errOut io.Writer
+ if opts.logErrors {
+ errOut = env.err
+ }
+
+ graphqlHandler := graphql.NewHandler(mrc, errOut)
// Routes
router.Path("/playground").Handler(playground.Handler("git-bug", "/graphql"))