brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 44e0a0e Raw
57 lines · python
1# DExTer : Debugging Experience Tester2# ~~~~~~   ~         ~~         ~   ~~3#4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5# See https://llvm.org/LICENSE.txt for license information.6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7"""Help tool."""8 9import textwrap10 11from dex.tools import ToolBase, get_tool_names, get_tools_directory, tool_main12from dex.utils.Imports import load_module13from dex.utils.ReturnCode import ReturnCode14 15 16class Tool(ToolBase):17    """Provides help info on subtools."""18 19    @property20    def name(self):21        return "DExTer help"22 23    @property24    def _visible_tool_names(self):25        return [t for t in get_tool_names() if not t.endswith("-")]26 27    def add_tool_arguments(self, parser, defaults):28        parser.description = Tool.__doc__29        parser.add_argument(30            "tool", choices=self._visible_tool_names, nargs="?", help="name of subtool"31        )32 33    def handle_options(self, defaults):34        pass35 36    @property37    def _default_text(self):38        s = "\n<b>The following subtools are available:</>\n\n"39        tools_directory = get_tools_directory()40        for tool_name in sorted(self._visible_tool_names):41            internal_name = tool_name.replace("-", "_")42            tool_doc = load_module(internal_name, tools_directory).Tool.__doc__43            tool_doc = tool_doc.strip() if tool_doc else ""44            tool_doc = textwrap.fill(" ".join(tool_doc.split()), 80)45            s += "<g>{}</>\n{}\n\n".format(tool_name, tool_doc)46        return s47 48    def go(self) -> ReturnCode:49        if self.context.options.tool is None:50            self.context.o.auto(self._default_text)51            return ReturnCode.OK52 53        tool_name = self.context.options.tool.replace("-", "_")54        tools_directory = get_tools_directory()55        module = load_module(tool_name, tools_directory)56        return tool_main(self.context, module.Tool(self.context), ["--help"])57