From 5cf15db6e4c6d7c5773ac2fa568033e425780efe Mon Sep 17 00:00:00 2001 From: Anderson Mesquita Date: Wed, 16 Dec 2015 10:11:01 -0500 Subject: [PATCH] Add command line option to open GUI (fixes #2210) --browser-only assumes syncthing is already running and will open the user's browser in the URL:port currently used in the configuration if the GUI is enabled. --- cmd/syncthing/main.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index cdd1d18e..46590f0d 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -198,6 +198,7 @@ var ( doUpgradeCheck bool upgradeTo string noBrowser bool + browserOnly bool noConsole bool logFile string auditEnabled bool @@ -232,6 +233,7 @@ func main() { flag.StringVar(&confDir, "home", "", "Set configuration directory") flag.IntVar(&logFlags, "logflags", logFlags, "Select information in log line prefix (see below)") flag.BoolVar(&noBrowser, "no-browser", false, "Do not start browser") + flag.BoolVar(&browserOnly, "browser-only", false, "Open GUI in browser") flag.BoolVar(&noRestart, "no-restart", noRestart, "Do not restart; just exit") flag.BoolVar(&reset, "reset", false, "Reset the database") flag.BoolVar(&doUpgrade, "upgrade", false, "Perform upgrade") @@ -282,6 +284,11 @@ func main() { return } + if browserOnly { + openGUI() + return + } + l.SetFlags(logFlags) if generateDir != "" { @@ -357,6 +364,18 @@ func main() { } } +func openGUI() { + cfg, _, err := loadConfig(locations[locConfigFile]) + if err != nil { + l.Fatalln("Config:", err) + } + if cfg.GUI().Enabled { + openURL(cfg.GUI().URL()) + } else { + l.Warnln("Browser: GUI is currently disabled") + } +} + func generate(generateDir string) { dir, err := osutil.ExpandTilde(generateDir) if err != nil {