Merge pull request #4603 from bhandras/fix_help

config: prevent displaying usage twice if --help was requested
This commit is contained in:
András Bánki-Horváth 2020-09-14 18:58:21 +02:00 committed by GitHub
commit dea6d91431
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -14,10 +14,16 @@ func main() {
// function will also set up logging properly. // function will also set up logging properly.
loadedConfig, err := lnd.LoadConfig() loadedConfig, err := lnd.LoadConfig()
if err != nil { if err != nil {
if e, ok := err.(*flags.Error); !ok || e.Type != flags.ErrHelp {
// Print error if not due to help request.
_, _ = fmt.Fprintln(os.Stderr, err) _, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1) os.Exit(1)
} }
// Help was requested, exit normally.
os.Exit(0)
}
// Hook interceptor for os signals. // Hook interceptor for os signals.
if err := signal.Intercept(); err != nil { if err := signal.Intercept(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err) _, _ = fmt.Fprintln(os.Stderr, err)
@ -26,14 +32,10 @@ func main() {
// Call the "real" main in a nested manner so the defers will properly // Call the "real" main in a nested manner so the defers will properly
// be executed in the case of a graceful shutdown. // be executed in the case of a graceful shutdown.
err = lnd.Main( if err := lnd.Main(
loadedConfig, lnd.ListenerCfg{}, signal.ShutdownChannel(), loadedConfig, lnd.ListenerCfg{}, signal.ShutdownChannel(),
) ); err != nil {
if err != nil {
if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp {
} else {
_, _ = fmt.Fprintln(os.Stderr, err) _, _ = fmt.Fprintln(os.Stderr, err)
}
os.Exit(1) os.Exit(1)
} }
} }