|
11 | 11 | from commitizen.config.factory import create_config |
12 | 12 | from commitizen.cz import registry |
13 | 13 | from commitizen.defaults import CONFIG_FILES, DEFAULT_SETTINGS |
14 | | -from commitizen.exceptions import InitFailedError, NoAnswersError |
| 14 | +from commitizen.exceptions import ( |
| 15 | + InitFailedError, |
| 16 | + MissingCzCustomizeConfigError, |
| 17 | + NoAnswersError, |
| 18 | +) |
15 | 19 | from commitizen.git import get_latest_tag_name, get_tag_names, smart_open |
16 | 20 | from commitizen.version_schemes import KNOWN_SCHEMES, Version, get_version_scheme |
17 | 21 |
|
@@ -167,12 +171,28 @@ def _ask_config_path(self) -> Path: |
167 | 171 | def _ask_name(self) -> str: |
168 | 172 | name: str = questionary.select( |
169 | 173 | "Please choose a cz (commit rule): (default: cz_conventional_commits)", |
170 | | - choices=list(registry.keys()), |
| 174 | + choices=self._construct_name_choice_with_description(), |
171 | 175 | default="cz_conventional_commits", |
172 | 176 | style=self.cz.style, |
173 | 177 | ).unsafe_ask() |
174 | 178 | return name |
175 | 179 |
|
| 180 | + def _construct_name_choice_with_description(self) -> list[questionary.Choice]: |
| 181 | + choices = [] |
| 182 | + for cz_name, cz_class in registry.items(): |
| 183 | + try: |
| 184 | + cz_obj = cz_class(self.config) |
| 185 | + except MissingCzCustomizeConfigError: |
| 186 | + choices.append(questionary.Choice(title=cz_name, value=cz_name)) |
| 187 | + continue |
| 188 | + first_example = cz_obj.schema().partition("\n")[0] |
| 189 | + choices.append( |
| 190 | + questionary.Choice( |
| 191 | + title=cz_name, value=cz_name, description=first_example |
| 192 | + ) |
| 193 | + ) |
| 194 | + return choices |
| 195 | + |
176 | 196 | def _ask_tag(self) -> str: |
177 | 197 | latest_tag = get_latest_tag_name() |
178 | 198 | if not latest_tag: |
|
0 commit comments