Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4ff2088

Browse files
bearomorphismLee-W
authored andcommitted
refactor(Init): use ternary operator
1 parent b35d343 commit 4ff2088

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

‎commitizen/commands/init.py‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ def __call__(self) -> None:
159159
out.success("Configuration complete 🚀")
160160

161161
def _ask_config_path(self) -> str:
162-
default_path = ".cz.toml"
163-
if self.project_info.has_pyproject:
164-
default_path="pyproject.toml"
162+
default_path = (
163+
"pyproject.toml"if self.project_info.has_pyprojectelse".cz.toml"
164+
)
165165

166166
name: str = questionary.select(
167167
"Please choose a supported config file: ",
@@ -270,15 +270,13 @@ def _ask_version_provider(self) -> str:
270270

271271
def _ask_version_scheme(self) -> str:
272272
"""Ask for setting: version_scheme"""
273-
default = "semver"
274-
if self.project_info.is_python:
275-
default = "pep440"
273+
default_scheme = "pep440" if self.project_info.is_python else "semver"
276274

277275
scheme: str = questionary.select(
278276
"Choose version scheme: ",
279-
choices=list(KNOWN_SCHEMES),
277+
choices=KNOWN_SCHEMES,
280278
style=self.cz.style,
281-
default=default,
279+
default=default_scheme,
282280
).unsafe_ask()
283281
return scheme
284282

@@ -318,10 +316,9 @@ def _gen_pre_commit_cmd(self, hook_types: list[str]) -> str:
318316
"""Generate pre-commit command according to given hook types"""
319317
if not hook_types:
320318
raise ValueError("At least 1 hook type should be provided.")
321-
cmd_str= "pre-commit install " + " ".join(
319+
return "pre-commit install " + " ".join(
322320
f"--hook-type {ty}" for ty in hook_types
323321
)
324-
return cmd_str
325322

326323
def _install_pre_commit_hook(self, hook_types: list[str] | None = None) -> None:
327324
pre_commit_config_filename = ".pre-commit-config.yaml"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /