Skip to content

Commit

Permalink
show input gets when requesting advanced help.
Browse files Browse the repository at this point in the history
# 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]
  • Loading branch information
kaos committed Jan 5, 2022
1 parent a587806 commit 2f32d4f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/python/pants/help/help_info_extracter.py
Expand Up @@ -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

Expand Down Expand Up @@ -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__),
)
Expand Down
15 changes: 13 additions & 2 deletions src/python/pants/help/help_printer.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 2f32d4f

Please sign in to comment.