Skip to content

Commit 36b7e2a

Browse files
committed
Improve usage information with GetoptError
- print to stderr - do not display help automatically
1 parent 209e3f0 commit 36b7e2a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

autorandr.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
from itertools import chain
3838
from collections import OrderedDict
3939

40+
import posix
41+
42+
4043
virtual_profiles = [
4144
# (name, description, callback)
4245
("common", "Clone all connected outputs at the largest common resolution", None),
@@ -606,8 +609,10 @@ def main(argv):
606609
try:
607610
options = dict(getopt.getopt(argv[1:], "s:l:d:cfh", [ "dry-run", "change", "default=", "save=", "load=", "force", "fingerprint", "config", "help" ])[0])
608611
except getopt.GetoptError as e:
609-
print(str(e))
610-
options = { "--help": True }
612+
print("Failed to parse options: {0}.\n"
613+
"Use --help to get usage information.".format(str(e)),
614+
file=sys.stderr)
615+
sys.exit(posix.EX_USAGE)
611616

612617
profiles = {}
613618
try:

0 commit comments

Comments
 (0)