From: Daniel Hahler Date: Sun, 17 May 2015 15:47:59 +0000 (+0200) Subject: Improve usage information with GetoptError X-Git-Tag: 1.0~50^2 X-Git-Url: https://git.donarmstrong.com/?p=deb_pkgs%2Fautorandr.git;a=commitdiff_plain;h=36b7e2ae7d43d995a9a9c2024c276654b429e12d Improve usage information with GetoptError - print to stderr - do not display help automatically --- diff --git a/autorandr.py b/autorandr.py index f9e9f4c..285c751 100755 --- a/autorandr.py +++ b/autorandr.py @@ -37,6 +37,9 @@ from distutils.version import LooseVersion as Version from itertools import chain from collections import OrderedDict +import posix + + virtual_profiles = [ # (name, description, callback) ("common", "Clone all connected outputs at the largest common resolution", None), @@ -606,8 +609,10 @@ def main(argv): try: options = dict(getopt.getopt(argv[1:], "s:l:d:cfh", [ "dry-run", "change", "default=", "save=", "load=", "force", "fingerprint", "config", "help" ])[0]) except getopt.GetoptError as e: - print(str(e)) - options = { "--help": True } + print("Failed to parse options: {0}.\n" + "Use --help to get usage information.".format(str(e)), + file=sys.stderr) + sys.exit(posix.EX_USAGE) profiles = {} try: