From: Jason Ish Date: Mon, 23 Jul 2018 21:31:52 +0000 (-0600) Subject: add-source: fix prompt for required fields X-Git-Tag: 1.0.0rc2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7ffd21c2244839ef3329b2e89e9ae518cecf23a;p=thirdparty%2Fsuricata-update.git add-source: fix prompt for required fields 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 --- diff --git a/CHANGELOG.md b/CHANGELOG.md index df89831..a9293ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/suricata/update/commands/addsource.py b/suricata/update/commands/addsource.py index fa3b1ce..902c1b3 100644 --- a/suricata/update/commands/addsource.py +++ b/suricata/update/commands/addsource.py @@ -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="", help="Name of source") - parser.add_argument("url", metavar="", help="Source URL") + parser.add_argument("name", metavar="", nargs="?", + help="Name of source") + parser.add_argument("url", metavar="", 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