Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/launchpad/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import click

from . import __version__
from .distribution.cli import distribution_command
from .service import run_service
from .size.cli import size_command
from .utils.console import console
Expand Down Expand Up @@ -81,6 +82,7 @@ def serve(host: str, port: int, mode: str | None, verbose: bool) -> None:


cli.add_command(size_command)
cli.add_command(distribution_command)


def main() -> None:
Expand Down
Empty file.
45 changes: 45 additions & 0 deletions src/launchpad/distribution/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from __future__ import annotations

from pathlib import Path

import click

from ..utils.android.apksigner import Apksigner, ApksignerError
from ..utils.console import console
from ..utils.logging import setup_logging


@click.command("distribution")
@click.argument("apk_path", type=click.Path(exists=True, path_type=Path))
@click.option("--verbose", "-v", is_flag=True, help="Enable verbose logging output.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should hoist --verbose to the outer level of the CLI at somepoint - but not in this PR.

def distribution_command(apk_path: Path, verbose: bool) -> None:
"""Print certificate information for an APK file.

Uses apksigner to extract and display the certificate information
from the specified APK file.
"""
setup_logging(verbose=verbose, quiet=False)

if not apk_path.suffix.lower() == ".apk":
console.print(f"[bold red]Error:[/bold red] File must be an APK file, got: {apk_path.suffix}")
raise click.Abort()

console.print(f"[bold blue]Analyzing APK certificate:[/bold blue] {apk_path}")

try:
apksigner = Apksigner()
cert_info = apksigner.get_certs(apk_path)
console.print("\n[bold green]Certificate Information:[/bold green]")
console.print(cert_info)
except ApksignerError as e:
console.print(f"[bold red]Error running apksigner:[/bold red] {e}")
if verbose:
console.print(f"Return code: {e.returncode}")
console.print(f"Stdout: {e.stdout}")
console.print(f"Stderr: {e.stderr}")
raise click.Abort()
except Exception as e:
console.print(f"[bold red]Unexpected error:[/bold red] {e}")
if verbose:
console.print_exception()
raise click.Abort()