Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions commitizen/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
from commitizen.config.factory import create_config
from commitizen.cz import registry
from commitizen.defaults import CONFIG_FILES, DEFAULT_SETTINGS
from commitizen.exceptions import InitFailedError, NoAnswersError
from commitizen.exceptions import (
InitFailedError,
NoAnswersError,
)
from commitizen.git import get_latest_tag_name, get_tag_names, smart_open
from commitizen.version_schemes import KNOWN_SCHEMES, Version, get_version_scheme

Expand Down Expand Up @@ -165,9 +168,25 @@ def _ask_config_path(self) -> Path:
return Path(filename)

def _ask_name(self) -> str:
def construct_choice_with_description(cz_name: str) -> questionary.Choice:
try:
cz_class = registry.get(cz_name)
if cz_class:
cz_obj = cz_class(self.config)
first_example = cz_obj.schema().partition("\n")[0]
return questionary.Choice(
title=cz_name, value=cz_name, description=f"{first_example}"
Comment thread
namwoam marked this conversation as resolved.
Outdated
)
except Exception: # pylint: disable=broad-except
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick question: what are possible exceptions

the try: block should be as small as possible

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cz_obj = cz_class(self.config) could cause exception MissingCzCustomizeConfigError for cz_customize, fixed except statement

pass
return questionary.Choice(title=cz_name, value=cz_name)

name: str = questionary.select(
"Please choose a cz (commit rule): (default: cz_conventional_commits)",
choices=list(registry.keys()),
choices=[
construct_choice_with_description(cz_name)
for cz_name in registry.keys()
],
default="cz_conventional_commits",
style=self.cz.style,
).unsafe_ask()
Expand Down