diff options
author | Matthias Andree <matthias.andree@gmx.de> | 2021-04-24 14:34:34 +0200 |
---|---|---|
committer | Matthias Andree <matthias.andree@gmx.de> | 2021-04-24 14:34:34 +0200 |
commit | 155b0bfa23b877110b35414d0f5d818c0f5906b6 (patch) | |
tree | 9891315852eb1e03bd23a11db92d287cb71073dd | |
parent | bd0bfc9c426720f506a5f44dd3bd85e7d03d3284 (diff) | |
download | fetchmail-155b0bfa23b877110b35414d0f5d818c0f5906b6.tar.gz fetchmail-155b0bfa23b877110b35414d0f5d818c0f5906b6.tar.bz2 fetchmail-155b0bfa23b877110b35414d0f5d818c0f5906b6.zip |
fetchmailconf: properly catch and report option parsing errors
-rw-r--r-- | NEWS | 3 | ||||
-rwxr-xr-x | fetchmailconf.py | 34 |
2 files changed, 27 insertions, 10 deletions
@@ -84,6 +84,9 @@ removed from a 6.5.0 or newer release.) -------------------------------------------------------------------------------- fetchmail-6.4.19: +# CHANGE: +* fetchmailconf: properly catch and report option parsing errors + # BUG FIX: * LMTP: do not try to validate the last component of a UNIX-domain LMTP socket as though it were a TCP port. Reported by Christoph Heitkamp, Gitlab issue #33. diff --git a/fetchmailconf.py b/fetchmailconf.py index 8722d48a..909975d1 100755 --- a/fetchmailconf.py +++ b/fetchmailconf.py @@ -35,13 +35,26 @@ except: # define a dummy class to inherit from class Frame: pass -VERSION = "1.63.4" +VERSION = "1.63.5" MIN_PY = (2, 7, 13) if sys.version_info < MIN_PY: sys.exit("fetchmailconf: Python %s.%s.%s or later is required.\n" % MIN_PY) # +# Display usage information and pass status argument through to sys.exit() +# +def usage(status): + print(""" +Usage: fetchmailconf {[-d] [-f fetchmailrc]|-h|--help|-V|--version} + -d - dump configuration (for debugging) + -f fmrc - read alternate fetchmailrc file +--help, -h - print this help text and quit +--version, -V - print fetchmailconf version and quit +""") + sys.exit(status) + +# # Define the data structures the GUIs will be tossing around # class Configuration(object): @@ -2185,7 +2198,12 @@ gUSiYASJpMEHhilJTEnhAlGoQqYAZQ1AiqEMZ0jDGtqQImhwwA13yMMevoQAGvGhEAWHGMOAAAA7 # # Process options - options, arguments = getopt.getopt(sys.argv[1:], "df:hV", ["help", "version"]) + try: + options, arguments = getopt.getopt(sys.argv[1:], "df:hV", ["help", "version"]) + except getopt.GetoptError as e: + usage(str(e)) + except Exception as e: + raise e dump = rcfile = None for (switch, val) in options: if switch == '-d': @@ -2193,14 +2211,7 @@ gUSiYASJpMEHhilJTEnhAlGoQqYAZQ1AiqEMZ0jDGtqQImhwwA13yMMevoQAGvGhEAWHGMOAAAA7 elif switch == '-f': rcfile = val elif switch == '-h' or switch == '--help': - print(""" -Usage: fetchmailconf {[-d] [-f fetchmailrc]|-h|--help|-V|--version} - -d - dump configuration (for debugging) - -f fmrc - read alternate fetchmailrc file ---help, -h - print this help text and quit ---version, -V - print fetchmailconf version and quit -""") - sys.exit(0) + usage(0) elif switch == '-V' or switch == '--version': print("fetchmailconf %s" % VERSION) print("Running on python", sys.version) @@ -2212,6 +2223,9 @@ welcome to redistribute it under certain conditions. Please see the file COPYING in the source or documentation directory for details.""") sys.exit(0) + if arguments: + usage("Extra arguments: '" + "' '".join(arguments) + "'") + if "DISPLAY" not in os.environ: sys.exit("fetchmailconf must be run under X") |