Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bases/polylith/cli/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List, Union

from polylith import commands, configuration, info, repo
from polylith.cli import build, create, env, options, test
from polylith.cli import build, create, delete, env, options, test
from typer import Exit, Option, Typer
from typing_extensions import Annotated

Expand All @@ -15,6 +15,13 @@
no_args_is_help=True,
)

app.add_typer(
delete.app,
name="delete",
help="Commands for deleting bases and components.",
no_args_is_help=True,
)

app.add_typer(
test.app,
name="test",
Expand Down
56 changes: 56 additions & 0 deletions bases/polylith/cli/delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from pathlib import Path

from polylith import commands, configuration, repo
from typer import Exit, Option, Typer
from typing_extensions import Annotated

app = Typer(no_args_is_help=True)


def _delete_brick(brick_type: str, name: str, dry_run: bool, force: bool) -> None:
root = repo.get_workspace_root(Path.cwd())
namespace = configuration.get_namespace_from_config(root)

cli_options = {
"brick_type": brick_type,
"name": name,
"dry_run": dry_run,
"force": force,
}

result = commands.delete.run(root, namespace, cli_options)

if not result:
raise Exit(code=1)


@app.command("component")
def component_command(
name: Annotated[str, Option(help="Name of the component to delete.")],
dry_run: Annotated[
bool, Option(help="Print what would be deleted, but do nothing.")
] = False,
force: Annotated[
bool,
Option(help="Delete even if other bricks/projects still use it."),
] = False,
):
"""Deletes a Polylith component (including generated tests)."""

_delete_brick("component", name, dry_run, force)


@app.command("base")
def base_command(
name: Annotated[str, Option(help="Name of the base to delete.")],
dry_run: Annotated[
bool, Option(help="Print what would be deleted, but do nothing.")
] = False,
force: Annotated[
bool,
Option(help="Delete even if other bricks/projects still use it."),
] = False,
):
"""Deletes a Polylith base (including generated tests)."""

_delete_brick("base", name, dry_run, force)
14 changes: 12 additions & 2 deletions components/polylith/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
from polylith.commands import check, create, deps, diff, info, libs, sync, test
from polylith.commands import check, create, delete, deps, diff, info, libs, sync, test

__all__ = ["check", "create", "deps", "diff", "info", "libs", "sync", "test"]
__all__ = [
"check",
"create",
"delete",
"deps",
"diff",
"info",
"libs",
"sync",
"test",
]
Loading