---
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 Arg2Choice, InstallArgs, InstallFlags, MycliArgs, MycliFlags, ShellChoice

class Mycli:
    def __init__(self, bin_path: str = "mycli") -> None:
        self._runner = CliRunner(bin_path)
        self.plugin = Plugin(self._runner)

    def exec(self, args: MycliArgs, flags: Optional[MycliFlags] = None) -> CliResult:
        """[FLAGS] <ARGS>… <SUBCOMMAND>"""
        cmd_args: list[str] = []
        if args.arg1 is not None: cmd_args.append(str(args.arg1))
        if args.arg2 is not None: cmd_args.append(str(args.arg2))
        if args.arg3 is not None: cmd_args.append(str(args.arg3))
        if args.argrest is not None: cmd_args.extend(args.argrest)
        if args.with_default is not None: cmd_args.append(str(args.with_default))
        flag_args = self._build_flag_args(flags)
        return self._runner.run(cmd_args + flag_args)

    def _build_flag_args(self, flags: Optional[MycliFlags]) -> list[str]:
        result: list[str] = []
        if flags is None: return result
        if flags.flag1: result.append("--flag1")
        if flags.flag2: result.append("--flag2")
        if flags.flag3: result.append("--flag3")
        elif flags.flag3 is False: result.append("--no-flag3")
        if flags.with_default: result.append("--with-default")
        if flags.shell is not None: result.extend(["--shell", str(flags.shell)])
        return result

class Plugin:
    def __init__(self, runner: CliRunner) -> None:
        self._runner = runner
        self.install = Install(self._runner)

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

class Install:
    """install a plugin"""
    def __init__(self, runner: CliRunner) -> None:
        self._runner = runner

    def exec(self, args: InstallArgs, flags: Optional[InstallFlags] = None) -> CliResult:
        """plugin install [FLAGS] <plugin> <version>"""
        cmd_args: list[str] = ["plugin", "install"]
        if args.plugin is not None: cmd_args.append(str(args.plugin))
        if args.version is not None: cmd_args.append(str(args.version))
        flag_args = self._build_flag_args(flags)
        return self._runner.run(cmd_args + flag_args)

    def _build_flag_args(self, flags: Optional[InstallFlags]) -> list[str]:
        result: list[str] = []
        if flags is None: return result
        if flags._global: result.append("--global")
        if flags._dir is not None: result.extend(["--dir", str(flags._dir)])
        if flags.force: result.append("--force")
        elif flags.force is False: result.append("--no-force")
        return result
