Add option to specify host address

Sascha created

'--host'-cmdline-option is added to the webui command.

Previously, the WebUI couldn't be hosted inside of a container. As the
WebUI-server only listend per default to localhost and there was no
option to change the address, the server should listend to. This means,
that the WebUI was only reachable from localhost. So only from inside of
the container but never from outside.
The '--host'-option allows to set the IP address or a hostname
which the WebUI-server should listen to. E.g. by setting 0.0.0.0 or ::
as address.

Update documentation for new option.

Update shell completion for new option.

Compilation seems to add another go-gitlab version.

Change summary

commands/webui.go            |  8 ++++++--
doc/man/git-bug-webui.1      |  6 +++++-
doc/md/git-bug_webui.md      | 11 ++++++-----
go.sum                       |  1 +
misc/bash_completion/git-bug |  4 ++++
5 files changed, 22 insertions(+), 8 deletions(-)

Detailed changes

commands/webui.go 🔗

@@ -4,9 +4,11 @@ import (
 	"context"
 	"fmt"
 	"log"
+	"net"
 	"net/http"
 	"os"
 	"os/signal"
+	"strconv"
 	"time"
 
 	"github.com/99designs/gqlgen/graphql/playground"
@@ -27,6 +29,7 @@ import (
 const webUIOpenConfigKey = "git-bug.webui.open"
 
 type webUIOptions struct {
+	host     string
 	port     int
 	open     bool
 	noOpen   bool
@@ -54,9 +57,10 @@ Available git config:
 	flags := cmd.Flags()
 	flags.SortFlags = false
 
+	flags.StringVar(&options.host, "host", "127.0.0.1", "Network address or hostname to listen to (default to 127.0.0.1)")
 	flags.BoolVar(&options.open, "open", false, "Automatically open the web UI in the default browser")
 	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 is random)")
+	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")
 
 	return cmd
@@ -71,7 +75,7 @@ func runWebUI(env *Env, opts webUIOptions, args []string) error {
 		}
 	}
 
-	addr := fmt.Sprintf("127.0.0.1:%d", opts.port)
+	addr := net.JoinHostPort(opts.host, strconv.Itoa(opts.port))
 	webUiAddr := fmt.Sprintf("http://%s", addr)
 
 	router := mux.NewRouter()

doc/man/git-bug-webui.1 🔗

@@ -21,6 +21,10 @@ Available git config:
 
 
 .SH OPTIONS
+.PP
+\fB\-\-host\fP="127.0.0.1"
+	Network address or hostname to listen to (default to 127.0.0.1)
+
 .PP
 \fB\-\-open\fP[=false]
 	Automatically open the web UI in the default browser
@@ -31,7 +35,7 @@ Available git config:
 
 .PP
 \fB\-p\fP, \fB\-\-port\fP=0
-	Port to listen to (default is random)
+	Port to listen to (default to random available port)
 
 .PP
 \fB\-\-read\-only\fP[=false]

doc/md/git-bug_webui.md 🔗

@@ -17,11 +17,12 @@ git-bug webui [flags]
 ### Options
 
 ```
-      --open        Automatically open the web UI in the default browser
-      --no-open     Prevent the automatic opening of the web UI in the default browser
-  -p, --port int    Port to listen to (default is random)
-      --read-only   Whether to run the web UI in read-only mode
-  -h, --help        help for webui
+      --host string   Network address or hostname to listen to (default to 127.0.0.1) (default "127.0.0.1")
+      --open          Automatically open the web UI in the default browser
+      --no-open       Prevent the automatic opening of the web UI in the default browser
+  -p, --port int      Port to listen to (default to random available port)
+      --read-only     Whether to run the web UI in read-only mode
+  -h, --help          help for webui
 ```
 
 ### SEE ALSO

go.sum 🔗

@@ -476,6 +476,7 @@ github.com/willf/bitset v1.1.10 h1:NotGKqX0KwQ72NUzqrjZq5ipPNDQex9lo3WpaS8L2sc=
 github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
 github.com/xanzy/go-gitlab v0.40.1 h1:jHueLh5Inzv20TL5Yki+CaLmyvtw3Yq7blbWx7GmglQ=
 github.com/xanzy/go-gitlab v0.40.1/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug=
+github.com/xanzy/go-gitlab v0.44.0 h1:cEiGhqu7EpFGuei2a2etAwB+x6403E5CvpLn35y+GPs=
 github.com/xanzy/go-gitlab v0.44.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug=
 github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
 github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI=

misc/bash_completion/git-bug 🔗

@@ -1331,6 +1331,10 @@ _git-bug_webui()
     flags_with_completion=()
     flags_completion=()
 
+    flags+=("--host=")
+    two_word_flags+=("--host")
+    local_nonpersistent_flags+=("--host")
+    local_nonpersistent_flags+=("--host=")
     flags+=("--open")
     local_nonpersistent_flags+=("--open")
     flags+=("--no-open")