Merge pull request #638 from thockin/v4-print-exit-flags-before-logs

Do print-and-exit flags before logging
This commit is contained in:
Kubernetes Prow Robot 2022-10-31 07:16:45 -07:00 committed by GitHub
commit 7ca48f8f14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 11 deletions

View File

@ -325,17 +325,7 @@ func main() {
pflag.Parse()
// Needs to happen very early for errors to be written to a file.
log := func() *logging.Logger {
if strings.HasPrefix(*flErrorFile, ".") {
fmt.Fprintf(os.Stderr, "ERROR: --error-file may not start with '.'")
os.Exit(1)
}
dir, file := filepath.Split(makeAbsPath(*flErrorFile, *flRoot))
return logging.New(dir, file, *flVerbose)
}()
cmdRunner := cmd.NewRunner(log)
// Handle print-and-exit cases.
if *flVersion {
fmt.Println(version.VERSION)
os.Exit(0)
@ -350,6 +340,17 @@ func main() {
os.Exit(0)
}
// Init logging very early, so most errors can be written to a file.
log := func() *logging.Logger {
if strings.HasPrefix(*flErrorFile, ".") {
fmt.Fprintf(os.Stderr, "ERROR: --error-file may not start with '.'")
os.Exit(1)
}
dir, file := filepath.Split(makeAbsPath(*flErrorFile, *flRoot))
return logging.New(dir, file, *flVerbose)
}()
cmdRunner := cmd.NewRunner(log)
if *flRepo == "" {
handleConfigError(log, true, "ERROR: --repo must be specified")
}