From 4678307483843c83eb38edce18a62b646a5e9d2e Mon Sep 17 00:00:00 2001 From: Esa Jokinen Date: Wed, 22 Sep 2021 17:16:23 +0300 Subject: [PATCH] chg: [lookup] use positional arguments for WORD(s) --- README.md | 28 +++++++++++++++------------- bin/lookup.py | 7 +------ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index dc42b18..f941f7a 100644 --- a/README.md +++ b/README.md @@ -50,53 +50,55 @@ curl -s -X POST https://cpe-guesser.cve-search.org/search -d "{\"query\": [\"out ### Command line - `lookup.py` ~~~~ -usage: lookup.py [-h] [--word WORD] +usage: lookup.py [-h] WORD [WORD ...] Find potential CPE names from a list of keyword(s) and return a JSON of the results +positional arguments: + WORD One or more keyword(s) to lookup + optional arguments: - -h, --help show this help message and exit - --word WORD One or more keyword(s) to lookup + -h, --help show this help message and exit ~~~~ ~~~~ -python3 lookup.py --word microsoft --word sql --word server | jq . +python3 lookup.py microsoft sql server | jq . [ [ - 51076, + 51325, "cpe:2.3:a:microsoft:sql_server_2017_reporting_services" ], [ - 51077, + 51326, "cpe:2.3:a:microsoft:sql_server_2019_reporting_services" ], [ - 57612, + 57898, "cpe:2.3:a:quest:intrust_knowledge_pack_for_microsoft_sql_server" ], [ - 60090, + 60386, "cpe:2.3:o:microsoft:sql_server" ], [ - 60660, + 60961, "cpe:2.3:a:microsoft:sql_server_desktop_engine" ], [ - 64489, + 64810, "cpe:2.3:a:microsoft:sql_server_reporting_services" ], [ - 75465, + 75858, "cpe:2.3:a:microsoft:sql_server_management_studio" ], [ - 77161, + 77570, "cpe:2.3:a:microsoft:sql_server" ], [ - 77793, + 78206, "cpe:2.3:a:ibm:tivoli_storage_manager_for_databases_data_protection_for_microsoft_sql_server" ] ] diff --git a/bin/lookup.py b/bin/lookup.py index de1e64f..e5ec5dd 100644 --- a/bin/lookup.py +++ b/bin/lookup.py @@ -12,13 +12,8 @@ from lib.cpeguesser import CPEGuesser if __name__ == '__main__': parser = argparse.ArgumentParser(description='Find potential CPE names from a list of keyword(s) and return a JSON of the results') - parser.add_argument('--word', help='One or more keyword(s) to lookup', action='append') + parser.add_argument('word', metavar='WORD', type=str, nargs='+', help='One or more keyword(s) to lookup') args = parser.parse_args() - if args.word is None: - print("Missing keyword(s)") - parser.print_help() - sys.exit(1) - cpeGuesser = CPEGuesser() print(json.dumps(cpeGuesser.guessCpe(args.word)))