From 3bf6cd2f21bbe00ea3d93a075859aacfd96dbb1a Mon Sep 17 00:00:00 2001 From: Alexey Tereshenkov <59651540+alexey-tereshenkov-oxb@users.noreply.github.com> Date: Tue, 8 Feb 2022 19:39:52 +0000 Subject: [PATCH 1/6] Make help command remind users about help-advanced command # 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_formatter.py | 12 +++++++++++- src/python/pants/help/help_formatter_test.py | 4 ++-- src/python/pants/help/help_printer.py | 18 ++++++++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/python/pants/help/help_formatter.py b/src/python/pants/help/help_formatter.py index 543a7750046..70cc32b6e63 100644 --- a/src/python/pants/help/help_formatter.py +++ b/src/python/pants/help/help_formatter.py @@ -14,8 +14,11 @@ class HelpFormatter(MaybeColor): - def __init__(self, *, show_advanced: bool, show_deprecated: bool, color: bool) -> None: + def __init__( + self, *, show_advanced: bool, show_deprecated: bool, color: bool, entity: str + ) -> None: super().__init__(color=color) + self.entity = entity self._show_advanced = show_advanced self._show_deprecated = show_deprecated self._width = terminal_width() @@ -49,6 +52,13 @@ def add_option(ohis, *, category=None): lines.extend([*self.format_option(ohi), ""]) add_option(oshi.basic) + if oshi.advanced and not self._show_advanced: + lines.append( + self.maybe_green( + f"There are advanced options which you can list by running " + f"`./pants help-advanced {self.entity}`" + ) + ) if self._show_advanced: add_option(oshi.advanced, category="advanced") if self._show_deprecated: diff --git a/src/python/pants/help/help_formatter_test.py b/src/python/pants/help/help_formatter_test.py index 89bf9f67434..d4e71ae134d 100644 --- a/src/python/pants/help/help_formatter_test.py +++ b/src/python/pants/help/help_formatter_test.py @@ -36,7 +36,7 @@ def _format_for_single_option(**kwargs): ) ohi = replace(ohi, **kwargs) lines = HelpFormatter( - show_advanced=False, show_deprecated=False, color=False + show_advanced=False, show_deprecated=False, color=False, entity="some" ).format_option(ohi) choices = kwargs.get("choices") assert len(lines) == 7 if choices else 6 @@ -67,7 +67,7 @@ def _format_for_global_scope(show_advanced, show_deprecated, args, kwargs): parser.parse_args(Parser.ParseArgsRequest((), OptionValueContainerBuilder(), [], False)) oshi = HelpInfoExtracter("").get_option_scope_help_info("", parser, False, "help.test") return HelpFormatter( - show_advanced=show_advanced, show_deprecated=show_deprecated, color=False + show_advanced=show_advanced, show_deprecated=show_deprecated, color=False, entity="some" ).format_options(oshi) def test_suppress_advanced(self): diff --git a/src/python/pants/help/help_printer.py b/src/python/pants/help/help_printer.py index 4c2da4b68c3..54ac75f21e3 100644 --- a/src/python/pants/help/help_printer.py +++ b/src/python/pants/help/help_printer.py @@ -268,16 +268,26 @@ def _print_options_help(self, scope: str, show_advanced_and_deprecated: bool) -> Assumes that self._help_request is an instance of OptionsHelp. """ + oshi = self._all_help_info.scope_to_help_info.get(scope) + if not oshi: + return + + # getting name of the entity for which the help needs to be shown + goal_info = self._all_help_info.name_to_goal_info.get(scope) + if goal_info: + entity = goal_info.name + else: + subsystem = self._all_help_info.scope_to_help_info.get(scope) + if subsystem: + entity = subsystem.scope + help_formatter = HelpFormatter( show_advanced=show_advanced_and_deprecated, show_deprecated=show_advanced_and_deprecated, color=self.color, + entity=entity, ) - oshi = self._all_help_info.scope_to_help_info.get(scope) - if not oshi: - return formatted_lines = help_formatter.format_options(oshi) - goal_info = self._all_help_info.name_to_goal_info.get(scope) if goal_info: related_scopes = sorted(set(goal_info.consumed_scopes) - {GLOBAL_SCOPE, goal_info.name}) if related_scopes: From 4ec6c2aa28cbe06409e7197c91cfed6113f10beb Mon Sep 17 00:00:00 2001 From: Alexey Tereshenkov <59651540+alexey-tereshenkov-oxb@users.noreply.github.com> Date: Wed, 9 Feb 2022 14:43:02 +0000 Subject: [PATCH 2/6] Get entity name from the readily available objects # 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_formatter.py | 7 ++----- src/python/pants/help/help_formatter_test.py | 4 ++-- src/python/pants/help/help_printer.py | 18 ++++-------------- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/python/pants/help/help_formatter.py b/src/python/pants/help/help_formatter.py index 70cc32b6e63..c0064ec739b 100644 --- a/src/python/pants/help/help_formatter.py +++ b/src/python/pants/help/help_formatter.py @@ -14,11 +14,8 @@ class HelpFormatter(MaybeColor): - def __init__( - self, *, show_advanced: bool, show_deprecated: bool, color: bool, entity: str - ) -> None: + def __init__(self, *, show_advanced: bool, show_deprecated: bool, color: bool) -> None: super().__init__(color=color) - self.entity = entity self._show_advanced = show_advanced self._show_deprecated = show_deprecated self._width = terminal_width() @@ -56,7 +53,7 @@ def add_option(ohis, *, category=None): lines.append( self.maybe_green( f"There are advanced options which you can list by running " - f"`./pants help-advanced {self.entity}`" + f"`./pants help-advanced {oshi.scope}`" ) ) if self._show_advanced: diff --git a/src/python/pants/help/help_formatter_test.py b/src/python/pants/help/help_formatter_test.py index d4e71ae134d..89bf9f67434 100644 --- a/src/python/pants/help/help_formatter_test.py +++ b/src/python/pants/help/help_formatter_test.py @@ -36,7 +36,7 @@ def _format_for_single_option(**kwargs): ) ohi = replace(ohi, **kwargs) lines = HelpFormatter( - show_advanced=False, show_deprecated=False, color=False, entity="some" + show_advanced=False, show_deprecated=False, color=False ).format_option(ohi) choices = kwargs.get("choices") assert len(lines) == 7 if choices else 6 @@ -67,7 +67,7 @@ def _format_for_global_scope(show_advanced, show_deprecated, args, kwargs): parser.parse_args(Parser.ParseArgsRequest((), OptionValueContainerBuilder(), [], False)) oshi = HelpInfoExtracter("").get_option_scope_help_info("", parser, False, "help.test") return HelpFormatter( - show_advanced=show_advanced, show_deprecated=show_deprecated, color=False, entity="some" + show_advanced=show_advanced, show_deprecated=show_deprecated, color=False ).format_options(oshi) def test_suppress_advanced(self): diff --git a/src/python/pants/help/help_printer.py b/src/python/pants/help/help_printer.py index 54ac75f21e3..4c2da4b68c3 100644 --- a/src/python/pants/help/help_printer.py +++ b/src/python/pants/help/help_printer.py @@ -268,26 +268,16 @@ def _print_options_help(self, scope: str, show_advanced_and_deprecated: bool) -> Assumes that self._help_request is an instance of OptionsHelp. """ - oshi = self._all_help_info.scope_to_help_info.get(scope) - if not oshi: - return - - # getting name of the entity for which the help needs to be shown - goal_info = self._all_help_info.name_to_goal_info.get(scope) - if goal_info: - entity = goal_info.name - else: - subsystem = self._all_help_info.scope_to_help_info.get(scope) - if subsystem: - entity = subsystem.scope - help_formatter = HelpFormatter( show_advanced=show_advanced_and_deprecated, show_deprecated=show_advanced_and_deprecated, color=self.color, - entity=entity, ) + oshi = self._all_help_info.scope_to_help_info.get(scope) + if not oshi: + return formatted_lines = help_formatter.format_options(oshi) + goal_info = self._all_help_info.name_to_goal_info.get(scope) if goal_info: related_scopes = sorted(set(goal_info.consumed_scopes) - {GLOBAL_SCOPE, goal_info.name}) if related_scopes: From 7933b7270c6efe027b22174293eee332e6032bfa Mon Sep 17 00:00:00 2001 From: Alexey Tereshenkov <59651540+alexey-tereshenkov-oxb@users.noreply.github.com> Date: Wed, 9 Feb 2022 14:58:53 +0000 Subject: [PATCH 3/6] Remind about advanced options last # 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_formatter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/python/pants/help/help_formatter.py b/src/python/pants/help/help_formatter.py index c0064ec739b..4dd51de1806 100644 --- a/src/python/pants/help/help_formatter.py +++ b/src/python/pants/help/help_formatter.py @@ -49,6 +49,10 @@ def add_option(ohis, *, category=None): lines.extend([*self.format_option(ohi), ""]) add_option(oshi.basic) + if self._show_advanced: + add_option(oshi.advanced, category="advanced") + if self._show_deprecated: + add_option(oshi.deprecated, category="deprecated") if oshi.advanced and not self._show_advanced: lines.append( self.maybe_green( @@ -56,10 +60,6 @@ def add_option(ohis, *, category=None): f"`./pants help-advanced {oshi.scope}`" ) ) - if self._show_advanced: - add_option(oshi.advanced, category="advanced") - if self._show_deprecated: - add_option(oshi.deprecated, category="deprecated") return [*lines, ""] def format_option(self, ohi: OptionHelpInfo) -> List[str]: From 7a3691550a52df3f3df8468afacf5bc374bb4e1f Mon Sep 17 00:00:00 2001 From: Alexey Tereshenkov <59651540+alexey-tereshenkov-oxb@users.noreply.github.com> Date: Wed, 9 Feb 2022 15:03:49 +0000 Subject: [PATCH 4/6] Fix unit test # 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_formatter_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/pants/help/help_formatter_test.py b/src/python/pants/help/help_formatter_test.py index 89bf9f67434..8657646698b 100644 --- a/src/python/pants/help/help_formatter_test.py +++ b/src/python/pants/help/help_formatter_test.py @@ -74,7 +74,7 @@ def test_suppress_advanced(self): args = ["--foo"] kwargs = {"advanced": True} lines = self._format_for_global_scope(False, False, args, kwargs) - assert len(lines) == 8 + assert len(lines) == 9 assert not any("--foo" in line for line in lines) lines = self._format_for_global_scope(True, False, args, kwargs) assert len(lines) == 18 From 3d4e5ce957ecbed3b7f69cd2034bc9bc8ac4a261 Mon Sep 17 00:00:00 2001 From: Alexey Tereshenkov <59651540+alexey-tereshenkov-oxb@users.noreply.github.com> Date: Wed, 9 Feb 2022 20:45:16 +0000 Subject: [PATCH 5/6] Reword the user message --- src/python/pants/help/help_formatter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python/pants/help/help_formatter.py b/src/python/pants/help/help_formatter.py index 4dd51de1806..15c15af870a 100644 --- a/src/python/pants/help/help_formatter.py +++ b/src/python/pants/help/help_formatter.py @@ -9,7 +9,7 @@ from pants.help.help_info_extracter import OptionHelpInfo, OptionScopeHelpInfo, to_help_str from pants.help.maybe_color import MaybeColor from pants.option.ranked_value import Rank, RankedValue -from pants.util.docutil import terminal_width +from pants.util.docutil import bin_name, terminal_width from pants.util.strutil import hard_wrap @@ -56,8 +56,8 @@ def add_option(ohis, *, category=None): if oshi.advanced and not self._show_advanced: lines.append( self.maybe_green( - f"There are advanced options which you can list by running " - f"`./pants help-advanced {oshi.scope}`" + f"Advanced options available. You can list them by running " + f"{bin_name()} help-advanced {oshi.scope}." ) ) return [*lines, ""] From bddec39c7006d9eed61e7913951f7e5e286aa18a Mon Sep 17 00:00:00 2001 From: Alexey Tereshenkov <59651540+alexey-tereshenkov-oxb@users.noreply.github.com> Date: Wed, 9 Feb 2022 21:50:06 +0000 Subject: [PATCH 6/6] Hardcode ./pants in the help message # 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_formatter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python/pants/help/help_formatter.py b/src/python/pants/help/help_formatter.py index 15c15af870a..2e26cc0041c 100644 --- a/src/python/pants/help/help_formatter.py +++ b/src/python/pants/help/help_formatter.py @@ -9,7 +9,7 @@ from pants.help.help_info_extracter import OptionHelpInfo, OptionScopeHelpInfo, to_help_str from pants.help.maybe_color import MaybeColor from pants.option.ranked_value import Rank, RankedValue -from pants.util.docutil import bin_name, terminal_width +from pants.util.docutil import terminal_width from pants.util.strutil import hard_wrap @@ -57,7 +57,7 @@ def add_option(ohis, *, category=None): lines.append( self.maybe_green( f"Advanced options available. You can list them by running " - f"{bin_name()} help-advanced {oshi.scope}." + f"./pants help-advanced {oshi.scope}." ) ) return [*lines, ""]