aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-03-07 14:09:15 +0100
committerMiklos Vajna <vmiklos@collabora.com>2021-03-07 14:11:04 +0100
commit626ec9835b4450fb2994ec931357279700437b6b (patch)
tree983dbee41bacb6614e0fe5ffb6318dfc2754c7ae /commands
parent87bc42fb4695872b82cfa9a922d423df7ff21132 (diff)
downloadgit-bug-626ec9835b4450fb2994ec931357279700437b6b.tar.gz
webui: allow specifying the initial query
Example use-case: given a github URL in a source code comment or commit message, one can now run: git bug webui --query 'metadata:github-url:"https://github.com/author/myproject/issues/42"' on the commandline to look up the details of that issue on the web ui quickly, offline. Fixes <https://github.com/MichaelMure/git-bug/issues/592>.
Diffstat (limited to 'commands')
-rw-r--r--commands/webui.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/commands/webui.go b/commands/webui.go
index d910a703..3857e968 100644
--- a/commands/webui.go
+++ b/commands/webui.go
@@ -6,6 +6,7 @@ import (
"log"
"net"
"net/http"
+ "net/url"
"os"
"os/signal"
"strconv"
@@ -34,6 +35,7 @@ type webUIOptions struct {
open bool
noOpen bool
readOnly bool
+ query string
}
func newWebUICommand() *cobra.Command {
@@ -62,6 +64,7 @@ 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.StringVar(&options.query, "query", "", "Set a custom query")
return cmd
}
@@ -78,6 +81,11 @@ func runWebUI(env *Env, opts webUIOptions, args []string) error {
addr := net.JoinHostPort(opts.host, strconv.Itoa(opts.port))
webUiAddr := fmt.Sprintf("http://%s", addr)
+ if len(opts.query) > 0 {
+ // Explicitly set the query parameter instead of going with a default one.
+ webUiAddr = fmt.Sprintf("%s/?q=%s", webUiAddr, url.QueryEscape(opts.query))
+ }
+
router := mux.NewRouter()
// If the webUI is not read-only, use an authentication middleware with a