Move setFlagDefaults closer to flag code

This commit is contained in:
Tim Hockin 2020-07-31 09:00:31 -07:00
parent 366e08ff40
commit af755fbe99
1 changed files with 10 additions and 11 deletions

View File

@ -200,6 +200,16 @@ func envDuration(key string, def time.Duration) time.Duration {
return def
}
func setFlagDefaults() {
// Force logging to stderr (from glog).
stderrFlag := flag.Lookup("logtostderr")
if stderrFlag == nil {
fmt.Fprintf(os.Stderr, "ERROR: can't find flag 'logtostderr'\n")
os.Exit(1)
}
stderrFlag.Value.Set("true")
}
func main() {
// In case we come up as pid 1, act as init.
if os.Getpid() == 1 {
@ -216,7 +226,6 @@ func main() {
}
setFlagDefaults()
flag.Parse()
if *flVer {
@ -400,16 +409,6 @@ func waitTime(seconds float64) time.Duration {
return time.Duration(int(seconds*1000)) * time.Millisecond
}
func setFlagDefaults() {
// Force logging to stderr.
stderrFlag := flag.Lookup("logtostderr")
if stderrFlag == nil {
fmt.Fprintf(os.Stderr, "can't find flag 'logtostderr'\n")
os.Exit(1)
}
stderrFlag.Value.Set("true")
}
// Do no work, but don't do something that triggers go's runtime into thinking
// it is deadlocked.
func sleepForever() {