Merge pull request #227 from farhadmak/issue-205

Resolves: non-option argument instead of --startup-url
pull/231/head
Tobi 2018-10-08 14:20:01 -04:00 zatwierdzone przez GitHub
commit 6c9e4beb94
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 20 dodań i 1 usunięć

Wyświetl plik

@ -4,6 +4,7 @@ import (
"encoding/base64"
"fmt"
"io/ioutil"
"net/url"
"os"
"os/exec"
"path/filepath"
@ -191,6 +192,17 @@ func ttyEntry() {
// MainEntry decides between running Browsh as a CLI app or as an HTTP web server
func MainEntry() {
pflag.Parse()
// validURL contains array of valid user inputted links.
var validURL []string
if pflag.NArg() != 0 {
for i := 0; i < len(pflag.Args()); i++ {
u, _ := url.ParseRequestURI(pflag.Args()[i])
if u != nil {
validURL = append(validURL, pflag.Args()[i])
}
}
}
viper.SetDefault("validURL", validURL)
Initialise()
if viper.GetBool("version") {
println(browshVersion)

Wyświetl plik

@ -147,7 +147,14 @@ func webSocketServer(w http.ResponseWriter, r *http.Request) {
}
// For some reason, using Firefox's CLI arg `--url https://google.com` doesn't consistently
// work. So we do it here instead.
sendMessageToWebExtension("/new_tab," + viper.GetString("startup-url"))
validURL := viper.GetStringSlice("validURL")
if len(validURL) == 0 {
sendMessageToWebExtension("/new_tab," + viper.GetString("startup-url"))
} else {
for i := 0; i < len(validURL); i++ {
sendMessageToWebExtension("/new_tab," + validURL[i])
}
}
}
func sendConfigToWebExtension() {