-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exception that handle error message printing in the cli (temporar…
…y fatorization) and use the only existing blitz app if there is only one and no blitz app name is specified
- Loading branch information
Showing
6 changed files
with
135 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,47 @@ | ||
from typing import Annotated | ||
from typing import Annotated, Optional | ||
from blitz import BlitzCore | ||
from blitz.app import ReleaseLevel | ||
import typer | ||
from rich import print | ||
import enum | ||
|
||
from blitz.db.errors import NoChangesDetectedError | ||
from blitz.db.errors import NoChangesDetectedError as MigrationNoChangesDetectedError | ||
from blitz.cli.errors import BlitzAppNotFoundError, MissingBlitzAppNameError, NoChangesDetectedError | ||
|
||
|
||
|
||
class ReleaseLevel(enum.Enum): | ||
major = "major" | ||
minor = "minor" | ||
patch = "patch" | ||
|
||
|
||
def release_blitz( | ||
blitz_app_name: Annotated[str, typer.Argument(..., help="Blitz app to release")], | ||
level: Annotated[ReleaseLevel, typer.Argument(..., help="Release level")], | ||
blitz_app_name: Annotated[Optional[str], typer.Argument(help="Blitz app to release")] = None, | ||
force: Annotated[bool, typer.Option(help="Force the release even if no changes are detected")] = False, | ||
patch: Annotated[bool, typer.Option(help="Release level patch")] = False, | ||
minor: Annotated[bool, typer.Option(help="Release level minor")] = False, | ||
major: Annotated[bool, typer.Option(help="Release level major")] = False, | ||
) -> None: | ||
# Can't have both --patch and --minor or --major | ||
if sum([patch, minor, major]) > 1: | ||
raise typer.BadParameter("You can't use more than one release level") | ||
release_level = ReleaseLevel.MAJOR if major else ReleaseLevel.MINOR if minor else ReleaseLevel.PATCH | ||
|
||
blitz = BlitzCore() | ||
|
||
app = blitz.get_app(blitz_app_name) | ||
if blitz_app_name is None: | ||
if len(blitz.apps) == 1: | ||
blitz_app = blitz.apps[0] | ||
else: | ||
raise MissingBlitzAppNameError() | ||
else: | ||
try: | ||
blitz_app = blitz.get_app(blitz_app_name) | ||
except Exception: | ||
raise BlitzAppNotFoundError(blitz_app_name) | ||
|
||
try: | ||
new_version = app.release(level.value, force=force) | ||
except NoChangesDetectedError: | ||
typer.echo("No changes detected since the latest version. Use --force to release anyway.") | ||
raise typer.Exit(code=1) | ||
typer.echo(f"Blitz app {blitz_app_name} released at version {new_version}") | ||
typer.echo("You can now start your versioned blitz app by running:") | ||
new_version = blitz_app.release(release_level, force=force) | ||
except MigrationNoChangesDetectedError: | ||
raise NoChangesDetectedError() | ||
|
||
print(f"Blitz app {blitz_app_name} released at version {new_version}") | ||
print("You can now start your versioned blitz app by running:") | ||
print(f" [bold medium_purple1]blitz start {blitz_app_name} --version {new_version}[/bold medium_purple1]") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import typer | ||
from rich import print | ||
|
||
from blitz.app import BlitzApp | ||
|
||
|
||
class BlitzCLIError(typer.Exit): | ||
CODE = 1 | ||
|
||
|
||
class BlitzAppNotFoundError(BlitzCLIError): | ||
def __init__(self, blitz_app_name: str) -> None: | ||
self.blitz_app_name = blitz_app_name | ||
print(f"[red bold]There is no blitz app named {blitz_app_name}[/red bold]") | ||
print("To list the available blitz apps run:") | ||
print("[bold] blitz list[bold]") | ||
super().__init__(code=self.CODE) | ||
|
||
|
||
class BlitzAppVersionNotFoundError(BlitzCLIError): | ||
def __init__(self, blitz_app: BlitzApp, version: str) -> None: | ||
self.blitz_app = blitz_app | ||
self.version = version | ||
print(f"[red bold]There is no version {version} for the blitz app {blitz_app.name}[/red bold]") | ||
print("Available versions are:") | ||
for blitz_app_version in blitz_app.versions: | ||
print(f" {blitz_app_version}") | ||
super().__init__(code=self.CODE) | ||
|
||
|
||
class MissingBlitzAppNameError(BlitzCLIError): | ||
def __init__(self) -> None: | ||
print("You need to specify a blitz app name.") | ||
print("To list the available blitz apps run:") | ||
print("[bold] blitz list[bold]") | ||
super().__init__(code=self.CODE) | ||
|
||
|
||
class NoChangesDetectedError(BlitzCLIError): | ||
def __init__(self) -> None: | ||
print("No changes detected since the latest version. Use --force to release anyway.") | ||
super().__init__(code=self.CODE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters