cli

assert _is_dict_annotation(dict)
assert _is_dict_annotation(Dict)
assert _is_dict_annotation(Dict[str, int])
assert _is_dict_annotation(Optional[Dict[str, str]])
assert _unwrap_optional(Dict[str, int]) == Dict[str, int]
assert _unwrap_optional(Optional[Dict[str, int]]) == Dict[str, int]
assert _unwrap_optional(str) == str
assert _unwrap_optional(Optional[str]) == str
assert _unwrap_optional(None) == None
class MyArg(BaseModel):
    name: str
    value: int

@_make_typer_compatible_func
def foo(arg1: MyArg, arg2: dict, arg3: int):
    print(arg1.model_dump())
    print(arg2)
    print(arg3)

foo(
    arg1='{"name": "test", "value": 42}',
    arg2='{"key": "value"}',
    arg3=123
)
{'name': 'test', 'value': 42}
{'key': 'value'}
123

create_controller_cli

create_controller_cli(
   controller: Controller,
   prepend_method_group: bool
) -> typer.Typer

Get the controller server instance.

Arguments: - controller (Controller): The controller to get the server for.

Returns: FastAPI: The controller server instance.


from ctrlstack import ctrl_cmd_method, ctrl_query_method, ctrl_method

class FooController(Controller):
    @ctrl_cmd_method
    def bar(self):
        pass
    
    @ctrl_cmd_method
    def bar2(self, arg: dict):
        print(f"Executing bar2 command with arg: {arg}")
    
    @ctrl_query_method
    def baz(self, x: int) -> str:
        pass
    
    @ctrl_method(ControllerMethodType.QUERY, "q")
    def qux(self):
        pass
    
app = create_controller_cli(FooController())
from typer.testing import CliRunner
runner = CliRunner()
result = runner.invoke(app, ["bar2", '{"key": "value"}'])
print(result.stdout)
Executing bar2 command with arg: {'key': 'value'}