New command

This commit is contained in:
Miroslav 2018-02-08 20:11:14 +02:00
parent 0cb38f6329
commit 9f78c36ec4
4 changed files with 13 additions and 20 deletions

View File

@ -50,9 +50,6 @@ CompletionState = typing.NamedTuple(
class CommandBuffer:
def __init__(self, master: mitmproxy.master.Master, start: str = "") -> None:
self.master = master
option_setting = start.startswith("set") and start.endswith("=")
if option_setting:
start += self.get_option_value(start)
self.text = self.flatten(start)
# Cursor is always within the range [0:len(buffer)].
self._cursor = len(self.text)
@ -97,11 +94,6 @@ class CommandBuffer:
ret.append(("commander_hint", "%s " % v))
return ret
def get_option_value(self, txt):
option = txt.rstrip("=").split()[1]
option_value = getattr(self.master.options, option, None)
return option_value if option_value else ""
def flatten(self, txt):
parts, _ = self.master.commands.parse_partial(txt)
return " ".join([x.value for x in parts])

View File

@ -277,6 +277,15 @@ class ConsoleAddon:
"""
signals.status_prompt_command.send(partial=" ".join(partial)) # type: ignore
@command.command("console.command.set")
def console_command_set(self, option: str) -> None:
"""Doc"""
option_value = getattr(self.master.options, option, None)
current_value = option_value if option_value else ""
self.master.commands.call(
"console.command set {}={}".format(option, current_value)
)
@command.command("console.view.keybindings")
def view_keybindings(self) -> None:
"""View the commands list."""

View File

@ -26,8 +26,8 @@ def map(km):
km.add("ctrl b", "console.nav.pageup", ["global"], "Page up")
km.add("I", "console.intercept.toggle", ["global"], "Toggle intercept")
km.add("i", "console.command set intercept=", ["global"], "Set intercept")
km.add("W", "console.command set save_stream_file=", ["global"], "Stream to file")
km.add("i", "console.command.set intercept", ["global"], "Set intercept")
km.add("W", "console.command.set save_stream_file", ["global"], "Stream to file")
km.add("A", "flow.resume @all", ["flowlist", "flowview"], "Resume all intercepted flows")
km.add("a", "flow.resume @focus", ["flowlist", "flowview"], "Resume this intercepted flow")
km.add(
@ -46,7 +46,7 @@ def map(km):
["flowlist", "flowview"],
"Export this flow to file"
)
km.add("f", "console.command set view_filter=", ["flowlist"], "Set view filter")
km.add("f", "console.command.set view_filter", ["flowlist"], "Set view filter")
km.add("F", "set console_focus_follow=toggle", ["flowlist"], "Set focus follow")
km.add(
"ctrl l",

View File

@ -1,4 +1,4 @@
from mitmproxy import options
from mitmproxy.tools.console.commander import commander
from mitmproxy.test import taddons
@ -96,11 +96,3 @@ class TestCommandBuffer:
with taddons.context() as tctx:
cb = commander.CommandBuffer(tctx.master)
assert cb.flatten("foo bar") == "foo bar"
def test_get_option_value(self):
opts = options.Options(view_filter="value")
with taddons.context(options=opts) as tctx:
cb = commander.CommandBuffer(tctx.master)
assert cb.get_option_value("set unknown_option=") == ""
assert cb.get_option_value("set intercept=") == ""
assert cb.get_option_value("set view_filter=") == "value"