---
source: lib/src/sdk/python/mod.rs
expression: "get_file(&output, \"client.py\")"
---
# @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 BuildArgs, BuildFlags, DeployArgs, DeployFlags, EnvChoice, GlobalFlags, MytoolArgs, MytoolFlags, TargetChoice

class Mytool:
    def __init__(self, bin_path: str = "mytool") -> None:
        self._runner = CliRunner(bin_path)
        self.build = Build(self._runner)
        self.deploy = Deploy(self._runner)

    def exec(self, args: MytoolArgs, flags: Optional[MytoolFlags] = None) -> CliResult:
        """[FLAGS] <input> <extra>… <SUBCOMMAND>"""
        cmd_args: list[str] = []
        if args._input is not None: cmd_args.append(str(args._input))
        if args.extra is not None: cmd_args.extend(args.extra)
        flag_args = self._build_flag_args(flags)
        return self._runner.run(cmd_args + flag_args)

    def _build_flag_args(self, flags: Optional[MytoolFlags]) -> list[str]:
        result: list[str] = []
        if flags is None: return result
        if flags.verbose is not None and flags.verbose > 0: result.extend(["--verbose"] * flags.verbose)
        if flags.config is not None: result.extend(["--config", str(flags.config)])
        if flags.dry_run: result.append("--dry-run")
        elif flags.dry_run is False: result.append("--no-dry-run")
        return result

    @property
    def b(self) -> Build:
        """Alias for build."""
        return self.build

class Build:
    """Build the project. DEPRECATED: Use compile instead. Aliases: b"""
    def __init__(self, runner: CliRunner) -> None:
        self._runner = runner

    def exec(self, args: BuildArgs, flags: Optional[BuildFlags] = None) -> CliResult:
        """build [-j --jobs… <n>] [--release] <target> <-- output>"""
        cmd_args: list[str] = ["build"]
        if args.target is not None: cmd_args.append(str(args.target))
        cmd_args.append("--")
        if args.output is not None: cmd_args.append(str(args.output))
        flag_args = self._build_flag_args(flags)
        return self._runner.run(cmd_args + flag_args)

    def _build_flag_args(self, flags: Optional[BuildFlags]) -> list[str]:
        result: list[str] = []
        if flags is None: return result
        if flags.verbose is not None and flags.verbose > 0: result.extend(["--verbose"] * flags.verbose)
        if flags.config is not None: result.extend(["--config", str(flags.config)])
        if flags.jobs is not None:
            for v in flags.jobs: result.extend(["--jobs", str(v)])
        if flags.release: result.append("--release")
        return result

class Deploy:
    """Deploy the project"""
    def __init__(self, runner: CliRunner) -> None:
        self._runner = runner

    def exec(self, args: DeployArgs, flags: Optional[DeployFlags] = None) -> CliResult:
        """deploy [-f --force] [--confirm] <env> <tags>…"""
        cmd_args: list[str] = ["deploy"]
        if args.env is not None: cmd_args.append(str(args.env))
        if args.tags is not None: cmd_args.extend(args.tags)
        flag_args = self._build_flag_args(flags)
        return self._runner.run(cmd_args + flag_args)

    def _build_flag_args(self, flags: Optional[DeployFlags]) -> list[str]:
        result: list[str] = []
        if flags is None: return result
        if flags.verbose is not None and flags.verbose > 0: result.extend(["--verbose"] * flags.verbose)
        if flags.config is not None: result.extend(["--config", str(flags.config)])
        if flags.force: result.append("--force")
        if flags.confirm: result.append("--confirm")
        return result
