diff options
-rw-r--r-- | mitmproxy/command.py | 4 | ||||
-rw-r--r-- | mitmproxy/tools/console/consoleaddons.py | 32 |
2 files changed, 21 insertions, 15 deletions
diff --git a/mitmproxy/command.py b/mitmproxy/command.py index 341a1401..8822bb9b 100644 --- a/mitmproxy/command.py +++ b/mitmproxy/command.py @@ -241,7 +241,7 @@ class CommandManager: raise exceptions.CommandError("Unknown command: %s" % command_name) return self.commands[command_name].func(*args) - def _call_strings(self, command_name: str, args: typing.Sequence[str]) -> typing.Any: + def call_strings(self, command_name: str, args: typing.Sequence[str]) -> typing.Any: """ Call a command using a list of string arguments. May raise CommandError. """ @@ -262,7 +262,7 @@ class CommandManager: for part in parts if part.type != mitmproxy.types.Space ] - return self._call_strings(command_name, args) + return self.call_strings(command_name, args) def dump(self, out=sys.stdout) -> None: cmds = list(self.commands.values()) diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index 8e99566d..617ac5e5 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -160,7 +160,7 @@ class ConsoleAddon: fv = self.master.window.current("options") if not fv: raise exceptions.CommandError("Not viewing options.") - self.master.commands.execute("options.reset.one %s" % command_lexer.quote(fv.current_name())) + self.master.commands.call_strings("options.reset.one", [fv.current_name()]) @command.command("console.nav.start") def nav_start(self) -> None: @@ -248,12 +248,13 @@ class ConsoleAddon: def callback(opt): # We're now outside of the call context... - repl = cmd + " " + " ".join(args) - repl = repl.replace("{choice}", opt) + repl = [arg.replace("{choice}", opt) for arg in args] try: - self.master.commands.execute(repl) + self.master.commands.call_strings(cmd, repl) except exceptions.CommandError as e: - signals.status_message.send(message=str(e)) + msg = str(e) + ctx.log.error(msg) + signals.status_message.send(message=msg) self.master.overlay( overlay.Chooser(self.master, prompt, choices, "", callback) @@ -276,9 +277,9 @@ class ConsoleAddon: def callback(opt): # We're now outside of the call context... - repl = " ".join(command_lexer.quote(x.replace("{choice}", opt)) for x in args) + repl = [arg.replace("{choice}", opt) for arg in args] try: - self.master.commands.execute(subcmd + " " + repl) + self.master.commands.call_strings(subcmd, repl) except exceptions.CommandError as e: msg = str(e) ctx.log.error(msg) @@ -455,8 +456,9 @@ class ConsoleAddon: url = edited_url.rstrip(b"\n") flow.request.url = url.decode() elif flow_part in ["method", "status_code", "reason"]: - self.master.commands.execute( - "console.command flow.set @focus %s " % command_lexer.quote(flow_part) + self.master.commands.call_strings( + "console.command", + ["flow.set", "@focus", flow_part] ) def _grideditor(self): @@ -540,8 +542,10 @@ class ConsoleAddon: raise exceptions.CommandError("Invalid flowview mode.") try: - cmd = 'view.settings.setval @focus flowview_mode_%s %s' % (idx, command_lexer.quote(mode)) - self.master.commands.execute(cmd) + self.master.commands.call_strings( + "view.settings.setval", + ["@focus", "flowview_mode_%s" % (idx,), mode] + ) except exceptions.CommandError as e: msg = str(e) ctx.log.error(msg) @@ -564,8 +568,10 @@ class ConsoleAddon: raise exceptions.CommandError("Not viewing a flow.") idx = fv.body.tab_offset - cmd = 'view.settings.getval @focus flowview_mode_%s %s' % (idx, command_lexer.quote(self.master.options.console_default_contentview)) - return self.master.commands.execute(cmd) + return self.master.commands.call_strings( + "view.settings.getval", + ["@focus", "flowview_mode_%s" % (idx,), self.master.options.console_default_contentview] + ) @command.command("console.key.contexts") def key_contexts(self) -> typing.Sequence[str]: |