commands: minor fixes for the webui open with query

Michael Muré created

- go fmt
- add a shorthand
- fix displayed webUI URL in the terminal

Change summary

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

Detailed changes

commands/webui.go 🔗

@@ -35,7 +35,7 @@ type webUIOptions struct {
 	open     bool
 	noOpen   bool
 	readOnly bool
-	query string
+	query    string
 }
 
 func newWebUICommand() *cobra.Command {
@@ -64,7 +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")
+	flags.StringVarP(&options.query, "query", "q", "", "The query to open in the web UI bug list")
 
 	return cmd
 }
@@ -80,10 +80,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)
+	toOpen := webUiAddr
 
 	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))
+		toOpen = fmt.Sprintf("%s/?q=%s", webUiAddr, url.QueryEscape(opts.query))
 	}
 
 	router := mux.NewRouter()
@@ -162,7 +163,7 @@ func runWebUI(env *Env, opts webUIOptions, args []string) error {
 	shouldOpen := (configOpen && !opts.noOpen) || opts.open
 
 	if shouldOpen {
-		err = open.Run(webUiAddr)
+		err = open.Run(toOpen)
 		if err != nil {
 			env.out.Println(err)
 		}

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

@@ -42,8 +42,8 @@ Available git config:
 	Whether to run the web UI in read\-only mode
 
 .PP
-\fB\-\-query\fP=""
-	Set a custom query
+\fB\-q\fP, \fB\-\-query\fP=""
+	The query to open in the web UI bug list
 
 .PP
 \fB\-h\fP, \fB\-\-help\fP[=false]

doc/md/git-bug_webui.md 🔗

@@ -22,7 +22,7 @@ git-bug webui [flags]
       --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
-      --query string   Set a custom query
+  -q, --query string   The query to open in the web UI bug list
   -h, --help           help for webui
 ```
 

go.sum 🔗

@@ -436,8 +436,6 @@ github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasO
 github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
 github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
 github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
-github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4=
-github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI=
 github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M=
 github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
 github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
@@ -474,8 +472,6 @@ github.com/vektah/gqlparser v1.3.1 h1:8b0IcD3qZKWJQHSzynbDlrtP3IxVydZ2DZepCGofqf
 github.com/vektah/gqlparser v1.3.1/go.mod h1:bkVf0FX+Stjg/MHnm8mEyubuaArhNEqfQhF+OTiAL74=
 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=
@@ -791,7 +787,6 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl
 gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
 gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=

misc/bash_completion/git-bug 🔗

@@ -1349,8 +1349,10 @@ _git-bug_webui()
     local_nonpersistent_flags+=("--read-only")
     flags+=("--query=")
     two_word_flags+=("--query")
+    two_word_flags+=("-q")
     local_nonpersistent_flags+=("--query")
     local_nonpersistent_flags+=("--query=")
+    local_nonpersistent_flags+=("-q")
 
     must_have_one_flag=()
     must_have_one_noun=()

repository/repo.go 🔗

@@ -11,7 +11,7 @@ import (
 )
 
 var (
-	// ErrNotARepo is the error returned when the git repo root wan't be found
+	// ErrNotARepo is the error returned when the git repo root can't be found
 	ErrNotARepo = errors.New("not a git repository")
 	// ErrClockNotExist is the error returned when a clock can't be found
 	ErrClockNotExist = errors.New("clock doesn't exist")