Do print-and-exit flags before logging

This commit is contained in:
Tim Hockin 2022-08-31 14:15:16 -07:00
parent 34c33c724a
commit 428169b87e
No known key found for this signature in database
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")
}