Do print-and-exit flags before logging
This commit is contained in:
parent
34c33c724a
commit
428169b87e
|
|
@ -325,17 +325,7 @@ func main() {
|
||||||
|
|
||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
|
|
||||||
// Needs to happen very early for errors to be written to a file.
|
// Handle print-and-exit cases.
|
||||||
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 *flVersion {
|
if *flVersion {
|
||||||
fmt.Println(version.VERSION)
|
fmt.Println(version.VERSION)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|
@ -350,6 +340,17 @@ func main() {
|
||||||
os.Exit(0)
|
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 == "" {
|
if *flRepo == "" {
|
||||||
handleConfigError(log, true, "ERROR: --repo must be specified")
|
handleConfigError(log, true, "ERROR: --repo must be specified")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue