Some further cleanup of switch parsing

This commit is contained in:
Veronica K. B. Olsen
2020-04-14 20:30:20 +02:00
parent f856a520d0
commit c942718575
+11 -10
View File
@@ -77,7 +77,7 @@ def main(sysArgs=None):
sysArgs = sys.argv[1:] sysArgs = sys.argv[1:]
# Valid Input Options # Valid Input Options
shortOpt = "hvidVql:" shortOpt = "hidvql:"
longOpt = [ longOpt = [
"help", "help",
"version", "version",
@@ -98,10 +98,10 @@ def main(sysArgs=None):
"\n" "\n"
"Usage:\n" "Usage:\n"
" -h, --help Print this message.\n" " -h, --help Print this message.\n"
" -v, --version Print program version and exit.\n" " --version Print program version and exit.\n"
" -i, --info Print additional runtime information.\n" " -i, --info Print additional runtime information.\n"
" -d, --debug Print debug output. Includes -i.\n" " -d, --debug Print debug output. Includes -i.\n"
" -V, --verbose Increase verbosity of debug output. Includes -d.\n" " -v, --verbose Increase verbosity of debug output. Includes -d.\n"
" -q, --quiet Disable output to command line. Does not affect log file.\n" " -q, --quiet Disable output to command line. Does not affect log file.\n"
" -l, --logfile= Specify log file.\n" " -l, --logfile= Specify log file.\n"
" --style= Sets Qt5 style flag. Defaults to 'Fusion'.\n" " --style= Sets Qt5 style flag. Defaults to 'Fusion'.\n"
@@ -130,8 +130,9 @@ def main(sysArgs=None):
# Parse Options # Parse Options
try: try:
inOpts, inRemain = getopt.getopt(sysArgs,shortOpt,longOpt) inOpts, inRemain = getopt.getopt(sysArgs,shortOpt,longOpt)
except getopt.GetoptError: except getopt.GetoptError as E:
print(helpMsg) print(helpMsg)
print("ERROR: %s" % str(E))
sys.exit(2) sys.exit(2)
if len(inRemain) > 0: if len(inRemain) > 0:
@@ -141,7 +142,7 @@ def main(sysArgs=None):
if inOpt in ("-h","--help"): if inOpt in ("-h","--help"):
print(helpMsg) print(helpMsg)
sys.exit() sys.exit()
elif inOpt in ("-v", "--version"): elif inOpt == "--version":
print("%s %s Version %s" % (__package__,__status__,__version__)) print("%s %s Version %s" % (__package__,__status__,__version__))
sys.exit() sys.exit()
elif inOpt in ("-i", "--info"): elif inOpt in ("-i", "--info"):
@@ -154,16 +155,16 @@ def main(sysArgs=None):
toFile = True toFile = True
elif inOpt in ("-q","--quiet"): elif inOpt in ("-q","--quiet"):
toStd = False toStd = False
elif inOpt in ("-V","--verbose"): elif inOpt in ("-v","--verbose"):
debugLevel = VERBOSE debugLevel = VERBOSE
logFormat = "[{asctime:}] {name:>30}:{lineno:<4d} {levelname:8} {message:}" logFormat = "[{asctime:}] {name:>30}:{lineno:<4d} {levelname:8} {message:}"
elif inOpt in ("--style"): elif inOpt == "--style":
qtStyle = inArg qtStyle = inArg
elif inOpt in ("--config"): elif inOpt == "--config":
confPath = inArg confPath = inArg
elif inOpt in ("--data"): elif inOpt == "--data":
dataPath = inArg dataPath = inArg
elif inOpt in ("--testmode"): elif inOpt == "--testmode":
testMode = True testMode = True
# Set Config Options # Set Config Options