aboutsummaryrefslogtreecommitdiffstats
path: root/fetchmailconf.py
diff options
context:
space:
mode:
authorMatthias Andree <matthias.andree@gmx.de>2021-04-24 14:34:34 +0200
committerMatthias Andree <matthias.andree@gmx.de>2021-04-24 14:34:34 +0200
commit155b0bfa23b877110b35414d0f5d818c0f5906b6 (patch)
tree9891315852eb1e03bd23a11db92d287cb71073dd /fetchmailconf.py
parentbd0bfc9c426720f506a5f44dd3bd85e7d03d3284 (diff)
downloadfetchmail-155b0bfa23b877110b35414d0f5d818c0f5906b6.tar.gz
fetchmail-155b0bfa23b877110b35414d0f5d818c0f5906b6.tar.bz2
fetchmail-155b0bfa23b877110b35414d0f5d818c0f5906b6.zip
fetchmailconf: properly catch and report option parsing errors
Diffstat (limited to 'fetchmailconf.py')
-rwxr-xr-xfetchmailconf.py34
1 files changed, 24 insertions, 10 deletions
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")