def function_parser(function, parser):
<EOL>parser.set_defaults(func=function)<EOL>help_text = inspect.getdoc(function)<EOL>main_text, params_help = parser_help_text(help_text)<EOL>args, varargs, keywords, defaults = inspect.getargspec(function)<EOL>if args is None:<EOL><INDENT>args = []<EOL><DEDENT>if defaults is None:<EOL><INDENT>defaults = []<EOL><DEDENT>if len(args) and args[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>args.pop(<NUM_LIT:0>)<EOL><DEDENT>num_required_args = len(args) - len(defaults)<EOL>for idx, arg in enumerate(args):<EOL><INDENT>if idx < num_required_args:<EOL><INDENT>arg_name, arg_params = calculate_default_type(arg, False, None, params_help)<EOL><DEDENT>else:<EOL><INDENT>default_value = defaults[idx - num_required_args]<EOL>arg_name, arg_params = calculate_default_type(arg, True, default_value, params_help)<EOL><DEDENT>parser.add_argument(arg_name, **arg_params)<EOL><DEDENT>
This function parses a function and adds its arguments to the supplied parser