From 62d46bfc3966d13849766b0d9b8a943b0c5abe11 Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Fri, 17 Jan 2020 14:31:13 +0000 Subject: [PATCH] added a help all super function that calls help_all first, and then loops over the parametr names to get more information --- binarycpython/utils/functions.py | 58 +++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py index fa525601b..756401682 100644 --- a/binarycpython/utils/functions.py +++ b/binarycpython/utils/functions.py @@ -7,6 +7,53 @@ from binarycpython.utils.custom_logging_functions import ( create_and_load_logging_function, ) +def get_help_super(print_help=False, return_dict=True): + """ + Function that first runs get_help_all, and then per argument also run the help function to get as much information as possible. + """ + + help_all_dict = get_help_all(print_help=False, return_dict=True) + + + # print(help_all_dict) + + # print(json.dumps(help_all_dict, indent=4)) + + help_all_super_dict = help_all_dict.copy() + + + for section_name in help_all_dict.keys(): + section = help_all_dict[section_name] + + # print(section) + for parameter_name in section['parameters'].keys(): + parameter = section['parameters'][parameter_name] + + detailed_help = get_help(parameter_name, print_help=False, return_dict=True, fail_silently=True) + + parameter['detailed_help'] = detailed_help + + if parameter['detailed_help']: + if not parameter['description']==parameter['detailed_help']['description']: + print(json.dumps(parameter, indent=4)) + + + # print(parameter['description']==parameter['detailed_help']['description']) + + + + + # print(parameter.keys()) + + if print_help: + print(json.dumps(help_all_super_dict, indent=4)) + + pass + + if return_dict: + return + + def get_help_all(print_help=True, return_dict=False): """ @@ -163,7 +210,7 @@ def get_arg_keys(): return get_defaults().keys() -def get_help(param_name, print_help=True, return_dict=False): +def get_help(param_name, print_help=True, return_dict=False, fail_silently=False): """ Function that returns the help info for a given parameter. @@ -245,11 +292,12 @@ def get_help(param_name, print_help=True, return_dict=False): return help_info_dict else: - print( - "{} is not a valid parameter name. Please choose from the following parameters:\n\t{}".format( - param_name, list(available_arg_keys) + if not fail_silently: + print( + "{} is not a valid parameter name. Please choose from the following parameters:\n\t{}".format( + param_name, list(available_arg_keys) + ) ) - ) return None -- GitLab