|
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 |
|
@@ -166,18 +170,20 @@ def _ask_config_path(self) -> Path: |
166 | 170 |
|
167 | 171 | def _ask_name(self) -> str: |
168 | 172 |
|
169 | | - def construct_choice_with_example(cz_name: str) -> questionary.Choice: |
170 | | - cz_class = registry.get(cz_name) |
171 | | - if cz_class: |
172 | | - first_example = cz_class.example().splitlines()[0] |
173 | | - title = f"{cz_name}: {first_example}" |
174 | | - return questionary.Choice(title=title, value=cz_name) |
| 173 | + def construct_choice_with_description(cz_name: str) -> questionary.Choice: |
| 174 | + try: |
| 175 | + cz_class = registry.get(cz_name)(self.config) |
| 176 | + if cz_class: |
| 177 | + first_example = cz_class.schema().partition("\n")[0] |
| 178 | + return questionary.Choice(title=cz_name, value=cz_name, description=f"{first_example}") |
| 179 | + except MissingCzCustomizeConfigError: |
| 180 | + pass |
175 | 181 | return questionary.Choice(title=cz_name, value=cz_name) |
176 | 182 |
|
177 | 183 | name: str = questionary.select( |
178 | 184 | "Please choose a cz (commit rule): (default: cz_conventional_commits)", |
179 | 185 | choices=[ |
180 | | - construct_choice_with_example(cz_name) for cz_name in registry.keys() |
| 186 | + construct_choice_with_description(cz_name) for cz_name in registry.keys() |
181 | 187 | ], |
182 | 188 | default="cz_conventional_commits", |
183 | 189 | style=self.cz.style, |
|
0 commit comments