Make the --help or -h options working when mandatory options are declared

Former-commit-id: db502ff81dcf20449d126978fcebf890edb814ae
This commit is contained in:
2023-03-21 22:01:20 +07:00
parent d09011fac2
commit 7ed567fbad

View File

@ -41,8 +41,22 @@ func GenerateOptionParser(optionset ...func(*getoptions.GetOpt)) ArgumentParser
remaining, err := options.Parse(args[1:])
if options.Called("help") {
fmt.Fprint(os.Stderr, options.Help())
os.Exit(1)
}
log.SetLevel(log.InfoLevel)
if options.Called("debug") {
log.SetLevel(log.DebugLevel)
log.Debugln("Switch to debug level logging")
}
// Handle user errors
if err != nil {
log.Fatalf("Error on the commande line : %v",err)
fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err)
fmt.Fprint(os.Stderr, options.Help(getoptions.HelpSynopsis))
os.Exit(1)
}
// Setup the maximum number of CPU usable by the program
@ -59,17 +73,6 @@ func GenerateOptionParser(optionset ...func(*getoptions.GetOpt)) ArgumentParser
log.Printf("No singleton option set")
}
if options.Called("help") {
fmt.Fprint(os.Stderr, options.Help())
os.Exit(1)
}
log.SetLevel(log.InfoLevel)
if options.Called("debug") {
log.SetLevel(log.DebugLevel)
log.Debugln("Switch to debug level logging")
}
return options, remaining
}
}