From 2f32d4f76faa2e2988666a617ea3662475a1b51f Mon Sep 17 00:00:00 2001 From: Andreas Stenius Date: Wed, 5 Jan 2022 17:31:36 +0100 Subject: [PATCH] show input gets when requesting advanced help. # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- src/python/pants/help/help_info_extracter.py | 2 ++ src/python/pants/help/help_printer.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/python/pants/help/help_info_extracter.py b/src/python/pants/help/help_info_extracter.py index 2cc5de47572b..685f11354601 100644 --- a/src/python/pants/help/help_info_extracter.py +++ b/src/python/pants/help/help_info_extracter.py @@ -237,6 +237,7 @@ class RuleInfo: help: str | None provider: str input_types: tuple[str, ...] + input_gets: tuple[str, ...] output_type: str output_desc: str | None @@ -431,6 +432,7 @@ def get_rule_infos( help=cls.maybe_cleandoc(rule.func.__doc__), provider=cls.get_first_provider(providers), input_types=tuple(selector.__name__ for selector in rule.input_selectors), + input_gets=tuple(str(constraints) for constraints in rule.input_gets), output_type=rule.output_type.__name__, output_desc=cls.maybe_cleandoc(rule.output_type.__doc__), ) diff --git a/src/python/pants/help/help_printer.py b/src/python/pants/help/help_printer.py index ebaf28fad72e..841496ebae0f 100644 --- a/src/python/pants/help/help_printer.py +++ b/src/python/pants/help/help_printer.py @@ -117,7 +117,7 @@ def _print_thing_help(self) -> None: elif thing in self._all_help_info.name_to_target_type_info: self._print_target_help(thing) elif thing in self._all_help_info.rule_output_type_to_rule_infos: - self._print_api_type_help(thing) + self._print_api_type_help(thing, help_request.advanced) else: print(self.maybe_red(f"Unknown entity: {thing}")) else: @@ -310,7 +310,7 @@ def _print_target_help(self, target_alias: str) -> None: print("\n" + formatted_desc) print() - def _print_api_type_help(self, output_type: str) -> None: + def _print_api_type_help(self, output_type: str, show_advanced: bool) -> None: self._print_title(f"`{output_type}` API type") rule_infos = self._all_help_info.rule_output_type_to_rule_infos[output_type] if rule_infos[0].output_desc: @@ -329,6 +329,17 @@ def _print_api_type_help(self, output_type: str) -> None: ) else: print(self.maybe_cyan(f"{indent}no inputs")) + if show_advanced and rule_info.input_gets: + print( + f"\n{indent}".join( + hard_wrap( + self.maybe_cyan(f"{pluralize(len(rule_info.input_gets), 'get')}: ") + + ", ".join(rule_info.input_gets), + indent=4, + width=self._width - 4, + ) + ) + ) if rule_info.description: print(f"{indent}{rule_info.description}") if rule_info.help: