---
source: lib/src/sdk/python/mod.rs
expression: client
---
# @generated by usage-cli from test.usage.kdl. Do not edit manually.
from __future__ import annotations
from typing import Optional
from .runtime import CliResult, CliRunner
from .types import CreateArgs, CreateFlags, RunFlags

class App:
    def __init__(self, bin_path: str = "app") -> None:
        self._runner = CliRunner(bin_path)
        self.db = Db(self._runner)

    def exec(self) -> CliResult:
        """<SUBCOMMAND>"""
        cmd_args: list[str] = []
        return self._runner.run(cmd_args)

class Db:
    """Database operations"""
    def __init__(self, runner: CliRunner) -> None:
        self._runner = runner
        self.migration = Migration(self._runner)

    def exec(self) -> CliResult:
        """db <SUBCOMMAND>"""
        cmd_args: list[str] = ["db"]
        return self._runner.run(cmd_args)

class Migration:
    """Migration management"""
    def __init__(self, runner: CliRunner) -> None:
        self._runner = runner
        self.create = Create(self._runner)
        self.run = Run(self._runner)

    def exec(self) -> CliResult:
        """db migration <SUBCOMMAND>"""
        cmd_args: list[str] = ["db", "migration"]
        return self._runner.run(cmd_args)

class Create:
    """Create a new migration"""
    def __init__(self, runner: CliRunner) -> None:
        self._runner = runner

    def exec(self, args: CreateArgs, flags: Optional[CreateFlags] = None) -> CliResult:
        """db migration create [--template <t>] <name>"""
        cmd_args: list[str] = ["db", "migration", "create"]
        if args.name is not None: cmd_args.append(str(args.name))
        flag_args = self._build_flag_args(flags)
        return self._runner.run(cmd_args + flag_args)

    def _build_flag_args(self, flags: Optional[CreateFlags]) -> list[str]:
        result: list[str] = []
        if flags is None: return result
        if flags.template is not None: result.extend(["--template", str(flags.template)])
        return result

class Run:
    """Run pending migrations"""
    def __init__(self, runner: CliRunner) -> None:
        self._runner = runner

    def exec(self, flags: Optional[RunFlags] = None) -> CliResult:
        """db migration run [--step <n>]"""
        cmd_args: list[str] = ["db", "migration", "run"]
        flag_args = self._build_flag_args(flags)
        return self._runner.run(cmd_args + flag_args)

    def _build_flag_args(self, flags: Optional[RunFlags]) -> list[str]:
        result: list[str] = []
        if flags is None: return result
        if flags.step is not None: result.extend(["--step", str(flags.step)])
        return result
