]> git.ipfire.org Git - thirdparty/suricata-update.git/commitdiff
arg handling: fix broken argument handling
authorJason Ish <ish@unx.ca>
Wed, 20 Jun 2018 21:01:53 +0000 (15:01 -0600)
committerJason Ish <ish@unx.ca>
Wed, 20 Jun 2018 21:01:53 +0000 (15:01 -0600)
Broke in 74bf64e706162de9bb1731e801609e0a667a27d8.

suricata/update/main.py

index 2b9335fcfc7b9950829e7a756f5e956c65c54886..59d5c2bfa0058da76226602727d90bdaf9872155 100644 (file)
@@ -1010,9 +1010,16 @@ def _main():
     global_parser.add_argument(
         "--no-check-certificate", action="store_true", default=None,
         help="Disable server SSL/TLS certificate verification")
+    global_parser.add_argument(
+        "-V", "--version", action="store_true", default=False,
+        help="Display version")
 
     global_args, rem = global_parser.parse_known_args()
 
+    if global_args.version:
+        print("suricata-update version %s (rev: %s)" % (version, revision))
+        return 0
+
     if not rem or rem[0].startswith("-"):
         rem.insert(0, "update")
 
@@ -1021,7 +1028,8 @@ def _main():
 
     # The "update" (default) sub-command parser.
     update_parser = subparsers.add_parser(
-        "update", add_help=False, parents=[global_parser])
+        "update", add_help=True, parents=[global_parser],
+        formatter_class=argparse.RawDescriptionHelpFormatter)
 
     update_parser.add_argument(
         "-o", "--output", metavar="<directory>", dest="output",
@@ -1076,19 +1084,25 @@ def _main():
                                help="Command to test Suricata configuration")
     update_parser.add_argument("--no-test", action="store_true", default=False,
                                help="Disable testing rules with Suricata")
-    update_parser.add_argument("-V", "--version", action="store_true", default=False,
-                               help="Display version")
     
     update_parser.add_argument("--no-merge", action="store_true", default=False,
                                help="Do not merge the rules into a single file")
 
-    update_parser.add_argument("-h", "--help", action="store_true")
-    
     # Hidden argument, --now to bypass the timebased bypass of
     # updating a ruleset.
     update_parser.add_argument(
         "--now", default=False, action="store_true", help=argparse.SUPPRESS)
 
+    update_parser.epilog = r"""other commands:
+    update-sources             Update the source index
+    list-sources               List available sources
+    enable-source              Enable a source from the index
+    disable-source             Disable an enabled source
+    remove-source              Remove an enabled or disabled source
+    list-enabled-sources       List all enabled sources
+    add-source                 Add a new source by URL
+"""
+
     # The Python 2.7 argparse module does prefix matching which can be
     # undesirable. Reserve some names here that would match existing
     # options to prevent prefix matching.
@@ -1133,26 +1147,6 @@ def _main():
     logger.debug("This is suricata-update version %s (rev: %s); Python: %s" % (
         version, revision, sys.version.replace("\n", "- ")))
 
-    if args.dump_sample_configs:
-        return dump_sample_configs()
-
-    if args.version:
-        print("suricata-update version %s (rev: %s)" % (version, revision))
-        return 0
-
-    if args.help:
-        print(update_parser.format_help())
-        print("""other commands:
-    update-sources             Update the source index
-    list-sources               List available sources
-    enable-source              Enable a source from the index
-    disable-source             Disable an enabled source
-    remove-source              Remove an enabled or disabled source
-    list-enabled-sources       List all enabled sources
-    add-source                 Add a new source by URL
-""")
-        return 0
-
     config.init(args)
     
     # Error out if any reserved/unimplemented arguments were set.
@@ -1211,6 +1205,9 @@ def _main():
             logger.error("Unknown command: %s", args.subcommand)
             return 1
 
+    if args.dump_sample_configs:
+        return dump_sample_configs()
+
     # If --no-ignore was provided, clear any ignores provided in the
     # config.
     if args.no_ignore: