Skip to content

Commit 7891d00

Browse files
committed
Reduce cogn complexity
1 parent 9e29cdd commit 7891d00

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

cli/loc.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,21 @@ def __parse_args(desc):
198198
return args
199199

200200

201-
def main():
201+
def __check_options(edition: str, kwargs: dict[str, str]) -> dict[str, str]:
202+
"""Verifies a certain number of options for compatibility with edition"""
203+
kwargs[options.FORMAT] = util.deduct_format(kwargs[options.FORMAT], kwargs[options.REPORT_FILE])
204+
if kwargs[options.WITH_BRANCHES] and edition == "community":
205+
util.exit_fatal(f"No branches in {edition} edition, aborting...", errcodes.UNSUPPORTED_OPERATION)
206+
if kwargs[options.COMPONENT_TYPE] == "portfolios" and edition in ("community", "developer"):
207+
util.exit_fatal(f"No portfolios in {edition} edition, aborting...", errcodes.UNSUPPORTED_OPERATION)
208+
if kwargs[options.COMPONENT_TYPE] == "portfolios" and kwargs[options.WITH_BRANCHES]:
209+
log.warning("Portfolio LoC export selected, branch option is ignored")
210+
kwargs[options.WITH_BRANCHES] = False
211+
return kwargs
212+
213+
214+
def main() -> None:
215+
"""sonar-loc entry point"""
202216
start_time = util.start_clock()
203217
try:
204218
kwargs = util.convert_args(
@@ -209,16 +223,7 @@ def main():
209223
except (options.ArgumentsError, exceptions.ConnectionError) as e:
210224
util.exit_fatal(e.message, e.errcode)
211225

212-
kwargs[options.FORMAT] = util.deduct_format(kwargs[options.FORMAT], kwargs[options.REPORT_FILE])
213-
214-
edition = endpoint.edition()
215-
if kwargs[options.WITH_BRANCHES] and edition == "community":
216-
util.exit_fatal(f"No branches in {edition} edition, aborting...", errcodes.UNSUPPORTED_OPERATION)
217-
if kwargs[options.COMPONENT_TYPE] == "portfolios" and edition in ("community", "developer"):
218-
util.exit_fatal(f"No portfolios in {edition} edition, aborting...", errcodes.UNSUPPORTED_OPERATION)
219-
if kwargs[options.COMPONENT_TYPE] == "portfolios" and kwargs[options.WITH_BRANCHES]:
220-
log.warning("Portfolio LoC export selected, branch option is ignored")
221-
kwargs[options.WITH_BRANCHES] = False
226+
kwargs = __check_options(endpoint.edition(), kwargs)
222227

223228
try:
224229
if kwargs[options.COMPONENT_TYPE] == "portfolios":

0 commit comments

Comments
 (0)