|
104 | 104 | import sys |
105 | 105 | import argparse |
106 | 106 | import datetime |
| 107 | +import contextlib |
| 108 | +import os |
107 | 109 |
|
108 | 110 | version = "22.03.29" |
109 | 111 |
|
@@ -280,7 +282,7 @@ def return_error_message(service_error, service_warning, data_error, output_erro |
280 | 282 | ########################################################################## |
281 | 283 | # set parser |
282 | 284 | ########################################################################## |
283 | | -def set_parser_arguments(): |
| 285 | +def set_parser_arguments(argsList=[]): |
284 | 286 | parser = argparse.ArgumentParser(formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=80, width=130)) |
285 | 287 | parser.add_argument('-a', action='store_true', default=False, dest='all', help='Print All Resources') |
286 | 288 | parser.add_argument('-ani', action='store_true', default=False, dest='allnoiam', help='Print All Resources but identity') |
@@ -332,7 +334,16 @@ def set_parser_arguments(): |
332 | 334 | parser.add_argument('-caches', action='store_true', default=False, dest='servicescr', help="Output Cache to screen (JSON format)") |
333 | 335 | parser.add_argument('--version', action='version', version='%(prog)s ' + version) |
334 | 336 |
|
335 | | - result = parser.parse_args() |
| 337 | + |
| 338 | + if not argsList: |
| 339 | + result = parser.parse_args() |
| 340 | + else: |
| 341 | + with contextlib.redirect_stdout(os.devnull): |
| 342 | + try: |
| 343 | + result = parser.parse_args(args=argsList) |
| 344 | + return result |
| 345 | + except Exception: |
| 346 | + return None |
336 | 347 |
|
337 | 348 | if len(sys.argv) < 2: |
338 | 349 | parser.print_help() |
@@ -489,4 +500,6 @@ def print_to_json_file(output, file_name, data, header): |
489 | 500 | ########################################################################## |
490 | 501 | # Main |
491 | 502 | ########################################################################## |
492 | | -execute_extract() |
| 503 | +if __name__ == "__main__": |
| 504 | + execute_extract() |
| 505 | + |
0 commit comments