99from piptools .locations import CACHE_DIR , DEFAULT_CONFIG_FILE_NAMES
1010from piptools .utils import UNSAFE_PACKAGES , override_defaults_from_config_file
1111
12+ _FC = _t .TypeVar ("_FC" , bound = "_t.Callable[..., _t.Any] | click.Command" )
13+
1214BuildTargetT = _t .Literal ["sdist" , "wheel" , "editable" ]
1315ALL_BUILD_TARGETS : tuple [BuildTargetT , ...] = (
1416 "editable" ,
1719)
1820
1921
22+ def help_option (* , epilog : str | None = None ) -> _t .Callable [[_FC ], _FC ]:
23+ """A variant of the built-in click ``--help`` option, customized for pip-tools.
24+
25+ Unlike ``click.help_option``, this decorator accepts its own ``epilog`` text which
26+ is printed *without indentation* after help text.
27+ """
28+
29+ def show_help (ctx : click .Context , param : click .Parameter , value : bool ) -> None :
30+ """Callback that print the help page on ``<stdout>`` and exits."""
31+ if value and not ctx .resilient_parsing :
32+ click .echo (ctx .get_help (), color = ctx .color )
33+ if epilog is not None :
34+ formatter = ctx .make_formatter ()
35+ formatter .write_text (epilog )
36+ click .echo ("\n " + formatter .getvalue ().rstrip ("\n " ), color = ctx .color )
37+ ctx .exit ()
38+
39+ return click .option ( # type: ignore[return-value]
40+ "-h" ,
41+ "--help" ,
42+ help = "Show this message and exit." ,
43+ callback = show_help ,
44+ is_eager = True ,
45+ expose_value = False ,
46+ is_flag = True ,
47+ )
48+
49+
2050def _get_default_option (option_name : str ) -> _t .Any :
2151 """
2252 Get default value of the pip's option (including option from pip.conf)
@@ -27,8 +57,6 @@ def _get_default_option(option_name: str) -> _t.Any:
2757 return getattr (default_values , option_name )
2858
2959
30- help_option_names = ("-h" , "--help" )
31-
3260# The options used by pip-compile and pip-sync are presented in no specific order.
3361
3462version = click .version_option (package_name = "pip-tools" )
0 commit comments