Skip to content

Commit 6a90185

Browse files
bearomorphismLee-W
authored andcommitted
refactor(bump): use a loop to shorten a series of similar NotAllowed exceptions
1 parent 9163ae2 commit 6a90185

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

commitizen/commands/bump.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -177,36 +177,22 @@ def __call__(self) -> None:
177177
build_metadata = self.arguments["build_metadata"]
178178
get_next = self.arguments["get_next"]
179179
allow_no_commit = self.arguments["allow_no_commit"]
180+
major_version_zero = self.arguments["major_version_zero"]
180181

181182
if manual_version:
182-
if increment:
183-
raise NotAllowed("--increment cannot be combined with MANUAL_VERSION")
184-
185-
if prerelease:
186-
raise NotAllowed("--prerelease cannot be combined with MANUAL_VERSION")
187-
188-
if devrelease is not None:
189-
raise NotAllowed("--devrelease cannot be combined with MANUAL_VERSION")
190-
191-
if is_local_version:
192-
raise NotAllowed(
193-
"--local-version cannot be combined with MANUAL_VERSION"
194-
)
195-
196-
if build_metadata:
197-
raise NotAllowed(
198-
"--build-metadata cannot be combined with MANUAL_VERSION"
199-
)
200-
201-
if self.bump_settings["major_version_zero"]:
202-
raise NotAllowed(
203-
"--major-version-zero cannot be combined with MANUAL_VERSION"
204-
)
205-
206-
if get_next:
207-
raise NotAllowed("--get-next cannot be combined with MANUAL_VERSION")
183+
for val, option in (
184+
(increment, "--increment"),
185+
(prerelease, "--prerelease"),
186+
(devrelease is not None, "--devrelease"),
187+
(is_local_version, "--local-version"),
188+
(build_metadata, "--build-metadata"),
189+
(major_version_zero, "--major-version-zero"),
190+
(get_next, "--get-next"),
191+
):
192+
if val:
193+
raise NotAllowed(f"{option} cannot be combined with MANUAL_VERSION")
208194

209-
if self.bump_settings["major_version_zero"] and current_version.release[0]:
195+
if major_version_zero and current_version.release[0]:
210196
raise NotAllowed(
211197
f"--major-version-zero is meaningless for current version {current_version}"
212198
)

0 commit comments

Comments
 (0)