diff --git a/src/serena/cli.py b/src/serena/cli.py index 457b3acb..6a3027de 100644 --- a/src/serena/cli.py +++ b/src/serena/cli.py @@ -468,15 +468,26 @@ class ToolCommands(AutoRegisteringGroup): ) @staticmethod - @click.command("list", help="Prints an overview of all tools implemented in Serena (not just the active ones for your project).") + @click.command( + "list", + help="Prints an overview of the tools that are active by default (not just the active ones for your project). For viewing all tools, pass `--all / -a`", + ) @click.option("--quiet", "-q", is_flag=True) - def list(quiet: bool = False) -> None: + @click.option("--all", "-a", "include_optional", is_flag=True, help="List all tools, including those not enabled by default.") + @click.option("--only-optional", is_flag=True, help="List only optional tools (those not enabled by default).") + def list(quiet: bool = False, include_optional: bool = False, only_optional: bool = False) -> None: tool_registry = ToolRegistry() if quiet: - for tool_name in tool_registry.get_tool_names_default_enabled(): + if only_optional: + tool_names = tool_registry.get_tool_names_optional() + elif include_optional: + tool_names = tool_registry.get_tool_names() + else: + tool_names = tool_registry.get_tool_names_default_enabled() + for tool_name in tool_names: click.echo(tool_name) else: - ToolRegistry().print_tool_overview() + ToolRegistry().print_tool_overview(include_optional=include_optional, only_optional=only_optional) @staticmethod @click.command( diff --git a/src/serena/tools/tools_base.py b/src/serena/tools/tools_base.py index 1f55e604..ebe289ad 100644 --- a/src/serena/tools/tools_base.py +++ b/src/serena/tools/tools_base.py @@ -363,18 +363,49 @@ class ToolRegistry: def get_all_tool_classes(self) -> list[type[Tool]]: return list(t.tool_class for t in self._tool_dict.values()) + def get_tool_classes_default_enabled(self) -> list[type[Tool]]: + """ + :return: the list of tool classes that are enabled by default (i.e. non-optional tools). + """ + return [t.tool_class for t in self._tool_dict.values() if not t.is_optional] + + def get_tool_classes_optional(self) -> list[type[Tool]]: + """ + :return: the list of tool classes that are optional (i.e. disabled by default). + """ + return [t.tool_class for t in self._tool_dict.values() if t.is_optional] + def get_tool_names_default_enabled(self) -> list[str]: """ :return: the list of tool names that are enabled by default (i.e. non-optional tools). """ return [t.tool_name for t in self._tool_dict.values() if not t.is_optional] - def print_tool_overview(self, tools: Iterable[type[Tool] | Tool] | None = None) -> None: + def get_tool_names_optional(self) -> list[str]: """ - Print a summary of the tools. If no tools are passed, a summary of all tools is printed. + :return: the list of tool names that are optional (i.e. disabled by default). + """ + return [t.tool_name for t in self._tool_dict.values() if t.is_optional] + + def get_tool_names(self) -> list[str]: + """ + :return: the list of all tool names. + """ + return list(self._tool_dict.keys()) + + def print_tool_overview( + self, tools: Iterable[type[Tool] | Tool] | None = None, include_optional: bool = False, only_optional: bool = False + ) -> None: + """ + Print a summary of the tools. If no tools are passed, a summary of the selection of tools (all, default or only optional) is printed. """ if tools is None: - tools = [tool.tool_class for tool in self._tool_dict.values() if not tool.is_optional] + if only_optional: + tools = self.get_tool_classes_optional() + elif include_optional: + tools = self.get_all_tool_classes() + else: + tools = self.get_tool_classes_default_enabled() tool_dict: dict[str, type[Tool] | Tool] = {} for tool_class in tools: