def autohelp_directive(dirname, arguments, options, content, lineno, content_offset, block_text, state, state_machine): """produces rst from nose help""" config = Config(parserClass=OptBucket, plugins=BuiltinPluginManager()) parser = config.getParser(TestProgram.usage()) rst = ViewList() for line in parser.format_help().split('\n'): rst.append(line, '<autodoc>') rst.append('Options', '<autodoc>') rst.append('-------', '<autodoc>') rst.append('', '<autodoc>') for opt in parser: rst.append(opt.options(), '<autodoc>') rst.append(' \n', '<autodoc>') rst.append(' ' + opt.help + '\n', '<autodoc>') rst.append('\n', '<autodoc>') node = nodes.section() node.document = state.document surrounding_title_styles = state.memo.title_styles surrounding_section_level = state.memo.section_level state.memo.title_styles = [] state.memo.section_level = 0 state.nested_parse(rst, 0, node, match_titles=1) state.memo.title_styles = surrounding_title_styles state.memo.section_level = surrounding_section_level return node.children
def __init__(self, name, app): """ Init command :param name: Name of the command :type name: str :param app: The application :type app: edmunds.application.Application """ super(TestCommand, self).__init__(name, app) # Fetch nose options config = Config(env=os.environ, files=all_config_files(), plugins=DefaultPluginManager()) nose_options = config.getParser(doc=TestProgram.usage()).option_list # Override run-function to be able to load the click-options dynamically # Dynamic click.option does not work for class-methods because of __click_params__ original_function = self.run def run_wrapper(**kwargs): return original_function(**kwargs) self.run = run_wrapper # Don't show --help nose_options = filter( lambda nose_option: '--help' not in nose_option._long_opts, nose_options) for nose_option in nose_options: args = nose_option._short_opts + nose_option._long_opts if not args: continue type_mapping = { 'string': str, 'int': int, 'long': int, 'float': float, # 'complex': str, # 'choice': str, } unsupported_attr = ['action', 'dest', 'const'] kwargs = {} for attr in OptParseOption.ATTRS: if attr in unsupported_attr: continue attr_value = getattr(nose_option, attr) if attr_value is None: continue if attr == 'type': attr_value = type_mapping[attr_value] if nose_option.nargs > 1: attr_value = click.Tuple([attr_value]) if attr == 'default': if attr_value == optparse.NO_DEFAULT: continue kwargs[attr] = attr_value click.option(*args[:2], **kwargs)(run_wrapper)