Commit 4d379bad authored by Adrian DC's avatar Adrian DC
Browse files

fix(entrypoint): refactor to return no error upon final actions

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 17889e95
Loading
Loading
Loading
Loading
+29 −20
Changes for src/cli/entrypoint.py: 29 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

# Standard libraries
from argparse import Namespace
from enum import Enum

# Modules libraries
from gitlab.exceptions import GitlabGetError
@@ -20,13 +21,17 @@ from ..types.namespaces import Namespaces
# Entrypoint class, pylint: disable=too-few-public-methods
class Entrypoint:

    # Enumerations
    Result = Enum('Result', ['SUCCESS', 'FINALIZE', 'ERROR'])

    # CLI, pylint: disable=too-many-branches
    @staticmethod
    def cli(options: Namespace) -> bool:
    def cli(options: Namespace) -> Result:

        # Variables
        group: GitLabGroup = None
        project: GitLabProject = None
        result: Entrypoint.Result = Entrypoint.Result.ERROR
        user: GitLabUser = None

        # Header
@@ -86,12 +91,13 @@ class Entrypoint:

            # Handle group
            if not options.exclude_group:
                if not Entrypoint.group(
                result = Entrypoint.group(
                    options,
                    gitlab,
                    group.full_path,
                ):
                    return False
                )
                if result in [Entrypoint.Result.FINALIZE, Entrypoint.Result.ERROR]:
                    return result

            # Iterate through subgroups
            if not options.exclude_subgroups:
@@ -104,13 +110,14 @@ class Entrypoint:
                        ),
                        key=lambda item: item.full_path,
                ):
                    if not Entrypoint.group(
                    result = Entrypoint.group(
                        options,
                        gitlab,
                        group_subgroup.full_path,
                        True,
                    ):
                        return False
                    )
                    if result in [Entrypoint.Result.FINALIZE, Entrypoint.Result.ERROR]:
                        return result

            # Iterate through projects
            if not options.exclude_projects:
@@ -123,12 +130,13 @@ class Entrypoint:
                        ),
                        key=lambda item: item.path_with_namespace,
                ):
                    if not Entrypoint.project(
                    result = Entrypoint.project(
                        options,
                        gitlab,
                        group_project.path_with_namespace,
                    ):
                        return False
                    )
                    if result in [Entrypoint.Result.FINALIZE, Entrypoint.Result.ERROR]:
                        return result

        # Handle user recursively
        elif user:
@@ -143,15 +151,16 @@ class Entrypoint:
                        ),
                        key=lambda item: item.path_with_namespace,
                ):
                    if not Entrypoint.project(
                    result = Entrypoint.project(
                        options,
                        gitlab,
                        user_project.path_with_namespace,
                    ):
                        return False
                    )
                    if result in [Entrypoint.Result.FINALIZE, Entrypoint.Result.ERROR]:
                        return result

        # Result
        return True
        return Entrypoint.Result.SUCCESS

    # Group
    @staticmethod
@@ -160,7 +169,7 @@ class Entrypoint:
        gitlab: GitLabFeature,
        criteria: str,
        subgroup: bool = False,
    ) -> bool:
    ) -> Result:

        # Acquire group
        group = gitlab.group(criteria)
@@ -193,7 +202,7 @@ class Entrypoint:
                  f'{Colors.RESET}')
            print(' ')
            Platform.flush()
            return subgroup
            return Entrypoint.Result.SUCCESS if subgroup else Entrypoint.Result.FINALIZE

        # Set group description
        if options.set_description:
@@ -249,7 +258,7 @@ class Entrypoint:
        Platform.flush()

        # Result
        return True
        return Entrypoint.Result.SUCCESS

    # Project, pylint: disable=too-many-branches,too-many-statements
    @staticmethod
@@ -257,7 +266,7 @@ class Entrypoint:
        options: Namespace,
        gitlab: GitLabFeature,
        criteria: str,
    ) -> bool:
    ) -> Result:

        # Acquire project
        project = gitlab.project(criteria)
@@ -277,7 +286,7 @@ class Entrypoint:
                  f'{Colors.RESET}')
            print(' ')
            Platform.flush()
            return True
            return Entrypoint.Result.SUCCESS

        # Set project description
        if options.set_description:
@@ -402,4 +411,4 @@ class Entrypoint:
        Platform.flush()

        # Result
        return True
        return Entrypoint.Result.SUCCESS
+2 −2
Changes for src/cli/main.py: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ def main() -> None:

    # Variables
    group: _ArgumentGroup
    result: bool = False
    result: Entrypoint.Result = Entrypoint.Result.ERROR
    subgroup: _MutuallyExclusiveGroup

    # Arguments creation
@@ -232,7 +232,7 @@ def main() -> None:
    Platform.flush()

    # Result
    if result:
    if result in [Entrypoint.Result.SUCCESS, Entrypoint.Result.FINALIZE]:
        sys_exit(0)
    else:
        sys_exit(1)