Returns the help option object. Skipped if :attr:`add_help_option` is ``False``. .. versionchanged:: 8.1.8 The help option is now cached to avoid creating it multiple times.
(self, ctx: Context)
| 1149 | return list(all_names) |
| 1150 | |
| 1151 | def get_help_option(self, ctx: Context) -> Option | None: |
| 1152 | """Returns the help option object. |
| 1153 | |
| 1154 | Skipped if :attr:`add_help_option` is ``False``. |
| 1155 | |
| 1156 | .. versionchanged:: 8.1.8 |
| 1157 | The help option is now cached to avoid creating it multiple times. |
| 1158 | """ |
| 1159 | help_option_names = self.get_help_option_names(ctx) |
| 1160 | |
| 1161 | if not help_option_names or not self.add_help_option: |
| 1162 | return None |
| 1163 | |
| 1164 | # Cache the help option object in private _help_option attribute to |
| 1165 | # avoid creating it multiple times. Not doing this will break the |
| 1166 | # callback ordering by iter_params_for_processing(), which relies on |
| 1167 | # object comparison. |
| 1168 | if self._help_option is None: |
| 1169 | # Avoid circular import. |
| 1170 | from .decorators import help_option |
| 1171 | |
| 1172 | # Apply help_option decorator and pop resulting option |
| 1173 | help_option(*help_option_names)(self) |
| 1174 | self._help_option = self.params.pop() # type: ignore[assignment] |
| 1175 | |
| 1176 | return self._help_option |
| 1177 | |
| 1178 | def make_parser(self, ctx: Context) -> _OptionParser: |
| 1179 | """Creates the underlying option parser for this command.""" |
no test coverage detected