options: choices for content views and tighten console order spec

Also clean up some leftovers from filter option name change.
This commit is contained in:
Aldo Cortesi 2017-03-19 13:39:28 +13:00
parent 22d7c31ea8
commit 43e7b9d68c
5 changed files with 13 additions and 13 deletions

View File

@ -300,13 +300,13 @@ class View(collections.Sequence):
# Event handlers
def configure(self, opts, updated):
if "filter" in updated:
if "view_filter" in updated:
filt = None
if opts.filter:
filt = flowfilter.parse(opts.filter)
if opts.view_filter:
filt = flowfilter.parse(opts.view_filter)
if not filt:
raise exceptions.OptionsError(
"Invalid interception filter: %s" % opts.filter
"Invalid interception filter: %s" % opts.view_filter
)
self.set_filter(filt)
if "console_order" in updated:

View File

@ -1,6 +1,7 @@
from typing import Optional, Sequence
from mitmproxy import optmanager
from mitmproxy import contentviews
from mitmproxy.net import tcp
# We redefine these here for now to avoid importing Urwid-related guff on
@ -154,7 +155,8 @@ class Options(optmanager.OptManager):
)
self.add_option(
"default_contentview", str, "auto",
"The default content view mode."
"The default content view mode.",
choices = [i.name for i in contentviews.views]
)
self.add_option(
"streamfile", Optional[str], None,
@ -390,7 +392,7 @@ class Options(optmanager.OptManager):
"Console mouse interaction."
)
self.add_option(
"console_order", Optional[str], None,
"console_order", str, "time",
"Flow sort order.",
choices=view_orders,
)

View File

@ -109,7 +109,7 @@ def mitmproxy(opts):
"See help in mitmproxy for filter expression syntax."
)
opts.make_parser(group, "intercept", metavar="FILTER")
opts.make_parser(group, "filter", metavar="FILTER")
opts.make_parser(group, "view_filter", metavar="FILTER")
return parser

View File

@ -207,7 +207,7 @@ class StatusBar(urwid.WidgetWrap):
r.append("[")
r.append(("heading_key", "M"))
r.append(":%s]" % self.master.options.default_contentview)
if self.master.options.console_order:
if self.master.options.has_changed("console_order"):
r.append("[")
r.append(("heading_key", "o"))
r.append(":%s]" % self.master.options.console_order)

View File

@ -264,7 +264,7 @@ def test_signals():
def test_focus_follow():
v = view.View()
with taddons.context(options=options.Options()) as tctx:
tctx.configure(v, console_focus_follow=True, filter="~m get")
tctx.configure(v, console_focus_follow=True, view_filter="~m get")
v.add(tft(start=5))
assert v.focus.index == 0
@ -378,9 +378,9 @@ def test_settings():
def test_configure():
v = view.View()
with taddons.context(options=options.Options()) as tctx:
tctx.configure(v, filter="~q")
tctx.configure(v, view_filter="~q")
with pytest.raises(Exception, match="Invalid interception filter"):
tctx.configure(v, filter="~~")
tctx.configure(v, view_filter="~~")
tctx.configure(v, console_order="method")
with pytest.raises(Exception, match="Unknown flow order"):
@ -388,7 +388,5 @@ def test_configure():
tctx.configure(v, console_order_reversed=True)
tctx.configure(v, console_order=None)
tctx.configure(v, console_focus_follow=True)
assert v.focus_follow