mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 03:14:22 +00:00
command: recursive command parsing
This lets us complete commands passed to commands correctly.
This commit is contained in:
parent
a436af537a
commit
582e6a9fa6
@ -181,13 +181,18 @@ class CommandManager:
|
|||||||
|
|
||||||
parse = [] # type: typing.List[ParseResult]
|
parse = [] # type: typing.List[ParseResult]
|
||||||
params = [] # type: typing.List[type]
|
params = [] # type: typing.List[type]
|
||||||
|
typ = None # type: typing.Type
|
||||||
for i in range(len(parts)):
|
for i in range(len(parts)):
|
||||||
if i == 0:
|
if i == 0:
|
||||||
params[:] = [Cmd]
|
typ = Cmd
|
||||||
if parts[i] in self.commands:
|
if parts[i] in self.commands:
|
||||||
params.extend(self.commands[parts[i]].paramtypes)
|
params.extend(self.commands[parts[i]].paramtypes)
|
||||||
if params:
|
elif params:
|
||||||
typ = params.pop(0)
|
typ = params.pop(0)
|
||||||
|
# FIXME: Do we need to check that Arg is positional?
|
||||||
|
if typ == Cmd and params and params[0] == Arg:
|
||||||
|
if parts[i] in self.commands:
|
||||||
|
params[:] = self.commands[parts[i]].paramtypes
|
||||||
else:
|
else:
|
||||||
typ = str
|
typ = str
|
||||||
parse.append(ParseResult(value=parts[i], type=typ))
|
parse.append(ParseResult(value=parts[i], type=typ))
|
||||||
|
@ -24,6 +24,10 @@ class TAddon:
|
|||||||
def cmd3(self, foo: int) -> int:
|
def cmd3(self, foo: int) -> int:
|
||||||
return foo
|
return foo
|
||||||
|
|
||||||
|
@command.command("subcommand")
|
||||||
|
def subcommand(self, cmd: command.Cmd, *args: command.Arg) -> str:
|
||||||
|
return "ok"
|
||||||
|
|
||||||
@command.command("empty")
|
@command.command("empty")
|
||||||
def empty(self) -> None:
|
def empty(self) -> None:
|
||||||
pass
|
pass
|
||||||
@ -102,6 +106,21 @@ class TestCommand:
|
|||||||
command.ParseResult(value = "", type = int),
|
command.ParseResult(value = "", type = int),
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
"subcommand ",
|
||||||
|
[
|
||||||
|
command.ParseResult(value = "subcommand", type = command.Cmd),
|
||||||
|
command.ParseResult(value = "", type = command.Cmd),
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"subcommand cmd3 ",
|
||||||
|
[
|
||||||
|
command.ParseResult(value = "subcommand", type = command.Cmd),
|
||||||
|
command.ParseResult(value = "cmd3", type = command.Cmd),
|
||||||
|
command.ParseResult(value = "", type = int),
|
||||||
|
]
|
||||||
|
],
|
||||||
]
|
]
|
||||||
with taddons.context() as tctx:
|
with taddons.context() as tctx:
|
||||||
tctx.master.addons.add(TAddon())
|
tctx.master.addons.add(TAddon())
|
||||||
|
Loading…
Reference in New Issue
Block a user