]> git.ipfire.org Git - thirdparty/suricata-update.git/commitdiff
add-source: fix prompt for required fields
authorJason Ish <ish@unx.ca>
Mon, 23 Jul 2018 21:31:52 +0000 (15:31 -0600)
committerJason Ish <ish@unx.ca>
Mon, 23 Jul 2018 21:36:51 +0000 (15:36 -0600)
The command had the code to prompt the user for the required
fields but the argument parser was forcing them to be set
on the command line. Make the name and url optional for
the argument parser, and prompt if not provided.

Also, handle user input on Python 2 and 3.

Fixes issue:
https://redmine.openinfosecfoundation.org/issues/2550

CHANGELOG.md
suricata/update/commands/addsource.py

index df89831b9ff058c403a1da97c3a2eaa4be6542a7..a9293ac5ea1daea36362661f1ae003bcf189ed08 100644 (file)
@@ -1,8 +1,10 @@
 # Change Log
 
 ## unreleased
-- Python 3 fix for  enable-source.
+- Python 3 fix for enable-source.
   https://redmine.openinfosecfoundation.org/issues/2549
+- Fix interactive input for add-source command.
+  https://redmine.openinfosecfoundation.org/issues/2550
 
 ## 1.0.0rc1 - 2018-07-17
 - Python 3 fixes.
index fa3b1ce457956ee8eae166f2837ae22abd009323..902c1b3b756f95203935cb1b0fc631704ddb3c60 100644 (file)
@@ -21,11 +21,17 @@ import logging
 from suricata.update import config
 from suricata.update import sources
 
+try:
+    input = raw_input
+except:
+    pass
+
 logger = logging.getLogger()
 
 def register(parser):
-    parser.add_argument("name", metavar="<name>", help="Name of source")
-    parser.add_argument("url", metavar="<url>", help="Source URL")
+    parser.add_argument("name", metavar="<name>", nargs="?",
+                        help="Name of source")
+    parser.add_argument("url", metavar="<url>", nargs="?", help="Source URL")
     parser.set_defaults(func=add_source)
 
 def add_source():
@@ -35,7 +41,7 @@ def add_source():
         name = args.name
     else:
         while True:
-            name = raw_input("Name of source: ").strip()
+            name = input("Name of source: ").strip()
             if name:
                 break
 
@@ -47,7 +53,7 @@ def add_source():
         url = args.url
     else:
         while True:
-            url = raw_input("URL: ").strip()
+            url = input("URL: ").strip()
             if url:
                 break