diff options
author | Rob Austein <sra@hactrn.net> | 2013-05-31 23:00:29 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2013-05-31 23:00:29 +0000 |
commit | afb1ad72334ca2430589953f8e5aeeb02d678cf5 (patch) | |
tree | 468ca667a9f5585e947ddcaf1b0bed9ddecb2bce | |
parent | 764d941d7d09123d0113b833a96abfa49c359677 (diff) |
--help should not backtrace, even if it does nothing very useful.
svn path=/trunk/; revision=5340
-rwxr-xr-x | rpkid/rpki-confgen | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/rpkid/rpki-confgen b/rpkid/rpki-confgen index 5331b514..0e34c48e 100755 --- a/rpkid/rpki-confgen +++ b/rpkid/rpki-confgen @@ -119,22 +119,35 @@ by $Id$ for o in self.options: o.to_conf(f, width) +# We use clunky getopt instead of shiny argparse because ordering of +# operations matters here, and most options may be repeated. No doubt +# there's a way to do this with argparse, but it's not obvious that +# it's worth the time it would take to figure it out. + sections = [] section_map = None option_map = None ident = None -opts, argv = getopt.getopt(sys.argv[1:], "", - ["read-xml=", - "write-xml=", - "write-wiki=", - "write-conf=", - "set=", - "pwgen=", - "autoconf"]) +try: + opts, argv = getopt.getopt(sys.argv[1:], "h", + ["help", + "read-xml=", + "write-xml=", + "write-wiki=", + "write-conf=", + "set=", + "pwgen=", + "autoconf"]) +except getopt.GetoptError, e: + sys.exit("%s: %s" % (sys.argv[0], e)) + for o, a in opts: - if o == "--read-xml": + if o in ("-h", "--help"): + sys.exit("Use the Source, Luke") + + elif o == "--read-xml": option_map = None root = ElementTree(file = a).getroot() ident = root.get("ident") @@ -210,4 +223,4 @@ for o, a in opts: section.to_conf(f, width) if argv: - sys.exit("Unexpected arguments %s" % argv) + sys.exit("%s: Unexpected argument%s: %s" % (sys.argv[0], "" if len(argv) == 1 else "s", " ".join(argv))) |