mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-03 12:28:28 +00:00
Extract cmdline option parsing into a new function
Another step towards reducing the general size of the main() function in favor of shorter, more focused functions.
This commit is contained in:
parent
a0b7ac402d
commit
4098f97735
@ -203,6 +203,9 @@ var (
|
|||||||
auditEnabled bool
|
auditEnabled bool
|
||||||
verbose bool
|
verbose bool
|
||||||
paused bool
|
paused bool
|
||||||
|
guiAddress string
|
||||||
|
guiAPIKey string
|
||||||
|
generateDir string
|
||||||
noRestart = os.Getenv("STNORESTART") != ""
|
noRestart = os.Getenv("STNORESTART") != ""
|
||||||
noUpgrade = os.Getenv("STNOUPGRADE") != ""
|
noUpgrade = os.Getenv("STNOUPGRADE") != ""
|
||||||
profiler = os.Getenv("STPROFILER")
|
profiler = os.Getenv("STPROFILER")
|
||||||
@ -212,7 +215,7 @@ var (
|
|||||||
innerProcess = os.Getenv("STNORESTART") != "" || os.Getenv("STMONITORED") != ""
|
innerProcess = os.Getenv("STNORESTART") != "" || os.Getenv("STMONITORED") != ""
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func parseCommandLineOptions() {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
// On Windows, we use a log file by default. Setting the -logfile flag
|
// On Windows, we use a log file by default. Setting the -logfile flag
|
||||||
// to "-" disables this behavior.
|
// to "-" disables this behavior.
|
||||||
@ -224,8 +227,6 @@ func main() {
|
|||||||
flag.StringVar(&logFile, "logfile", "-", "Log file name (use \"-\" for stdout)")
|
flag.StringVar(&logFile, "logfile", "-", "Log file name (use \"-\" for stdout)")
|
||||||
}
|
}
|
||||||
|
|
||||||
var guiAddress, guiAPIKey string
|
|
||||||
var generateDir string
|
|
||||||
flag.StringVar(&generateDir, "generate", "", "Generate key and config in specified dir, then exit")
|
flag.StringVar(&generateDir, "generate", "", "Generate key and config in specified dir, then exit")
|
||||||
flag.StringVar(&guiAddress, "gui-address", guiAddress, "Override GUI address (e.g. \"http://192.0.2.42:8443\")")
|
flag.StringVar(&guiAddress, "gui-address", guiAddress, "Override GUI address (e.g. \"http://192.0.2.42:8443\")")
|
||||||
flag.StringVar(&guiAPIKey, "gui-apikey", guiAPIKey, "Override GUI API key")
|
flag.StringVar(&guiAPIKey, "gui-apikey", guiAPIKey, "Override GUI API key")
|
||||||
@ -245,6 +246,10 @@ func main() {
|
|||||||
longUsage := fmt.Sprintf(extraUsage, baseDirs["config"], debugFacilities())
|
longUsage := fmt.Sprintf(extraUsage, baseDirs["config"], debugFacilities())
|
||||||
flag.Usage = usageFor(flag.CommandLine, usage, longUsage)
|
flag.Usage = usageFor(flag.CommandLine, usage, longUsage)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
parseCommandLineOptions()
|
||||||
|
|
||||||
if guiAddress != "" {
|
if guiAddress != "" {
|
||||||
// The config picks this up from the environment.
|
// The config picks this up from the environment.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user