Skip to content

Commit

Permalink
chore: move part-specific call to LifecyclePartsCommand
Browse files Browse the repository at this point in the history
Signed-off-by: Callahan Kovacs <callahankovacs@gmail.com>
  • Loading branch information
mr-cal committed May 8, 2024
1 parent a4764a9 commit d26b016
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions craft_application/commands/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ def _run(
shell = getattr(parsed_args, "shell", False)
shell_after = getattr(parsed_args, "shell_after", False)
debug = getattr(parsed_args, "debug", False)
parts = getattr(parsed_args, "parts", None)

step_name = step_name or self.name

Expand All @@ -198,10 +197,7 @@ def _run(
shell_after = True

try:
self._services.lifecycle.run(
step_name=step_name,
part_names=parts,
)
self._run_lifecycle(parsed_args, step_name)
except Exception as err:
if debug:
emit.progress(str(err), permanent=True)
Expand All @@ -211,6 +207,14 @@ def _run(
if shell_after:
_launch_shell()

def _run_lifecycle(
self,
parsed_args: argparse.Namespace, # noqa: ARG002 (unused argument is for subclasses)
step_name: str | None = None,
) -> None:
"""Run the lifecycle."""
self._services.lifecycle.run(step_name=step_name)

@staticmethod
def _should_add_shell_args() -> bool:
return True
Expand All @@ -233,6 +237,16 @@ def _fill_parser(self, parser: argparse.ArgumentParser) -> None:
help="Optional list of parts to process",
)

@override
def _run_lifecycle(
self, parsed_args: argparse.Namespace, step_name: str | None = None
) -> None:
"""Run the lifecycle, optionally for a part or list of parts."""
self._services.lifecycle.run(
step_name=step_name,
part_names=parsed_args.parts,
)


class PullCommand(LifecyclePartsCommand):
"""Command to pull parts."""
Expand Down

0 comments on commit d26b016

Please sign in to comment.