Skip to content

Commit

Permalink
fix: revert entrypoint_base and do not subclass init entrypoint
Browse files Browse the repository at this point in the history
Signed-off-by: George Vauter <[email protected]>
  • Loading branch information
gvauter committed Aug 20, 2024
1 parent bb6c4df commit 8c08bd6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
20 changes: 4 additions & 16 deletions trestlebot/entrypoints/entrypoint_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,8 @@
class EntrypointBase:
"""Base class for all entrypoints."""

def __init__(
self,
parser: argparse.ArgumentParser,
required_git_args: bool = True,
optional_git_args: bool = True,
provider_git_args: bool = True,
) -> None:
def __init__(self, parser: argparse.ArgumentParser) -> None:
self.parser: argparse.ArgumentParser = parser
self.required_git_args = required_git_args
self.optional_git_args = optional_git_args
self.provider_git_args = provider_git_args
self.setup_common_arguments()

def setup_common_arguments(self) -> None:
Expand All @@ -69,12 +60,9 @@ def setup_common_arguments(self) -> None:
action="store_true",
help="Run tasks, but do not push to the repository",
)
if self.required_git_args is True:
self._set_required_git_args()
if self.optional_git_args is True:
self._set_optional_git_args()
if self.provider_git_args is True:
self._set_git_provider_args()
self._set_required_git_args()
self._set_optional_git_args()
self._set_git_provider_args()

def _set_required_git_args(self) -> None:
"""Create an argument group for required git-related configuration."""
Expand Down
27 changes: 18 additions & 9 deletions trestlebot/entrypoints/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
TRESTLEBOT_CONFIG_DIR,
TRESTLEBOT_KEEP_FILE,
)
from trestlebot.entrypoints.entrypoint_base import EntrypointBase, handle_exception
from trestlebot.entrypoints.entrypoint_base import handle_exception
from trestlebot.entrypoints.log import set_log_level_from_args
from trestlebot.tasks.authored import types as model_types

Expand All @@ -45,7 +45,7 @@
OSCAL_MODEL_COMPDEF = model_types.AuthoredType.COMPDEF.value


class InitEntrypoint(EntrypointBase):
class InitEntrypoint:
"""Entrypoint for the init command."""

TEMPLATES_MODULE = "trestlebot.entrypoints.templates"
Expand Down Expand Up @@ -79,20 +79,30 @@ class InitEntrypoint(EntrypointBase):
"component-definitions",
"catalogs",
"profiles",
"rules",
],
}

def __init__(self, parser: argparse.ArgumentParser) -> None:
super().__init__(
parser,
required_git_args=False,
optional_git_args=False,
provider_git_args=False,
)
self.parser: argparse.ArgumentParser = parser
self.setup_init_arguments()

def setup_init_arguments(self) -> None:
"""Setup arguments for the init entrypoint."""
self.parser.add_argument(
"-v",
"--verbose",
help="Display verbose output",
action="count",
default=0,
)
self.parser.add_argument(
"--working-dir",
type=str,
required=False,
default=".",
help="Working directory wit git repository",
)
self.parser.add_argument(
"--provider",
required=False,
Expand All @@ -111,7 +121,6 @@ def setup_init_arguments(self) -> None:

def _call_trestle_init(self, args: argparse.Namespace) -> None:
"""Call compliance-trestle to initialize workspace"""
logger.debug("Calling compliance-trestle init command")
trestle_args = argparse.Namespace(
verbose=args.verbose,
trestle_root=pathlib.Path(args.working_dir),
Expand Down

0 comments on commit 8c08bd6

Please sign in to comment.