diff --git a/mitmproxy/command.py b/mitmproxy/command.py index 2db2b9f1d..4726bbc95 100644 --- a/mitmproxy/command.py +++ b/mitmproxy/command.py @@ -155,20 +155,22 @@ class CommandManager(mitmproxy.types._CommandBase): parts: typing.List[str] = lexer.get_tokens(cmdstr) if not parts: parts = [""] + elif cmdstr.endswith(" "): + parts.append("") parse: typing.List[ParseResult] = [] params: typing.List[type] = [] typ: typing.Type = None - for i in range(len(parts)): + for i, part in enumerate(parts): if i == 0: typ = mitmproxy.types.Cmd - if parts[i] in self.commands: - params.extend(self.commands[parts[i]].paramtypes) - elif params and not parts[i].isspace(): + if part in self.commands: + params.extend(self.commands[part].paramtypes) + elif params and not part.isspace(): typ = params.pop(0) if typ == mitmproxy.types.Cmd and params and params[0] == mitmproxy.types.Arg: - if parts[i] in self.commands: - params[:] = self.commands[parts[i]].paramtypes + if part in self.commands: + params[:] = self.commands[part].paramtypes else: typ = mitmproxy.types.Unknown @@ -176,7 +178,7 @@ class CommandManager(mitmproxy.types._CommandBase): valid = False if to: try: - to.parse(self, typ, parts[i]) + to.parse(self, typ, part) except exceptions.TypeError: valid = False else: @@ -184,7 +186,7 @@ class CommandManager(mitmproxy.types._CommandBase): parse.append( ParseResult( - value=parts[i], + value=part, type=typ, valid=valid, ) diff --git a/mitmproxy/tools/console/commander/commander.py b/mitmproxy/tools/console/commander/commander.py index 52330d285..94a7c4b41 100644 --- a/mitmproxy/tools/console/commander/commander.py +++ b/mitmproxy/tools/console/commander/commander.py @@ -141,7 +141,7 @@ class CommandBuffer: ) if self.completion: nxt = self.completion.completer.cycle() - buf = "".join([i.value for i in self.completion.parse[:-1]]) + "" + nxt + buf = "".join([i.value for i in self.completion.parse[:-1]]) + nxt buf = buf.strip() self.text = self.flatten(buf) self.cursor = len(self.text)