diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py index bf04fb0220867a7494a24674b656886416844a54..e94845dae2e6be74368db72c7d990104b8ff7721 100644 --- a/binarycpython/utils/functions.py +++ b/binarycpython/utils/functions.py @@ -42,7 +42,7 @@ def get_arg_keys(): return get_defaults().keys() -def get_help(param_name): +def get_help(param_name, return_dict): """ Function that returns the help info for a given parameter. @@ -52,33 +52,61 @@ def get_help(param_name): - default - available macros - + This function reads out that structure and catches the different components of this output + Presenting it in """ if param_name in get_arg_keys(): help_info = binary_c_python_api.return_help(param_name) + cleaned = [el for el in help_info.split('\n') if not el==''] - # print(help_info) + # Get line numbers + did_you_mean_nr = [i for i, el in enumerate(cleaned) if el.startswith('Did you mean')] + parameter_line_nr = [i for i, el in enumerate(cleaned) if el.startswith('binary_c help')] + default_line_nr = [i for i, el in enumerate(cleaned) if el.startswith('Default')] + macros_line_nr = [i for i, el in enumerate(cleaned) if el.startswith('Available')] - # print(help_info) - # print(help_info.split('\n')) - print(repr(help_info)) + help_info_dict = {} + + # Get alternatives + if did_you_mean_nr: + alternatives = cleaned[did_you_mean_nr[0]+1: parameter_line_nr[0]] + alternatives = [el.strip() for el in alternatives] + help_info_dict['alternatives'] = alternatives + + # Information about the parameter + parameter_line = cleaned[parameter_line_nr[0]] + parameter_name = parameter_line.split(":")[1].strip().split(' ')[0] + parameter_value_input_type = ' '.join(parameter_line.split(":")[1].strip().split(' ')[1:]).replace('<', '').replace('>', '') + + help_info_dict['parameter_name'] = parameter_name + help_info_dict['parameter_value_input_type'] = parameter_value_input_type + + description_line = ' '.join(cleaned[parameter_line_nr[0]+1 : default_line_nr[0]]) + help_info_dict['description'] = description_line + + # Default: + default_line = cleaned[default_line_nr[0]] + default_value = default_line.split(':')[-1].strip() + + help_info_dict['default'] = default_value + + # Get Macros: + if macros_line_nr: + macros = cleaned[macros_line_nr[0]+1:] + help_info_dict['macros'] = macros - cleaned = [el for el in help_info.split('\n') if not el==''] - did_you_mean_nr = [i for i, el in enumerate(cleaned) if el.startswith('Did you mean')][0] - parameter_line_nr = [i for i, el in enumerate(cleaned) if el.startswith('binary_c help')][0] - default_line_nr = [i for i, el in enumerate(cleaned) if el.startswith('Default')][0] - # macros_line_nr = [i for i, el in enumerate(cleaned) if el.startswith('available')][0] + for key in help_info_dict.keys(): + print("{}:\n\t{}".format(key, help_info_dict[key])) - # print(cleaned) - # print(info_line) + if return_dict: + return help_info_dict - pass -get_help('RLOF_method') +get_help('RLOF_method', return_dict=True)