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]])
cli
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):
str
name: int
value:
@_make_typer_compatible_func
def foo(arg1: MyArg, arg2: dict, arg3: int):
print(arg1.model_dump())
print(arg2)
print(arg3)
foo(='{"name": "test", "value": 42}',
arg1='{"key": "value"}',
arg2=123
arg3 )
{'name': 'test', 'value': 42}
{'key': 'value'}
123
create_controller_cli
create_controller_cli(
controller: Controller,bool
prepend_method_group: -> 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
= create_controller_cli(FooController()) app
from typer.testing import CliRunner
= CliRunner()
runner = runner.invoke(app, ["bar2", '{"key": "value"}'])
result print(result.stdout)
Executing bar2 command with arg: {'key': 'value'}