Coverage for tests/test_app/management/commands/callback2.py: 100%
15 statements
« prev ^ index » next coverage.py v7.3.4, created at 2024-01-20 18:02 +0000
« prev ^ index » next coverage.py v7.3.4, created at 2024-01-20 18:02 +0000
1import json
3from django_typer import TyperCommand, command, initialize
6class Command(TyperCommand, invoke_without_command=True):
7 help = "Test basic callback command."
9 parameters = {}
11 @initialize(
12 context_settings={
13 "allow_interspersed_args": True,
14 "ignore_unknown_options": True,
15 }
16 )
17 def init(self, p1: int, flag1: bool = False, flag2: bool = True):
18 """
19 The callback to initialize the command.
20 """
21 assert self.__class__ == Command
22 self.parameters = {"p1": p1, "flag1": flag1, "flag2": flag2}
23 return json.dumps(self.parameters)
25 @command(
26 context_settings={
27 "allow_interspersed_args": True,
28 "ignore_unknown_options": True,
29 }
30 )
31 def handle(self, arg1: str, arg2: str, arg3: float = 0.5, arg4: int = 1):
32 assert self.__class__ == Command
33 self.parameters.update({"arg1": arg1, "arg2": arg2, "arg3": arg3, "arg4": arg4})
34 return json.dumps(self.parameters)