aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2017-03-07 13:16:28 +1300
committerAldo Cortesi <aldo@nullcube.com>2017-03-07 13:16:28 +1300
commit99a6b0dbc1cc68bbcdbae1060a6f75ff4f0e9bf8 (patch)
tree078444dd0217ef17502e26b0c0af6d6bd4b05df3
parentd13df40753a3e8259ef4d2f25d9cb0c1e8141223 (diff)
downloadmitmproxy-99a6b0dbc1cc68bbcdbae1060a6f75ff4f0e9bf8.tar.gz
mitmproxy-99a6b0dbc1cc68bbcdbae1060a6f75ff4f0e9bf8.tar.bz2
mitmproxy-99a6b0dbc1cc68bbcdbae1060a6f75ff4f0e9bf8.zip
Add --options that dumps annotated option defaults
-rw-r--r--mitmproxy/optmanager.py20
-rw-r--r--mitmproxy/tools/cmdline.py5
-rw-r--r--mitmproxy/tools/main.py14
-rw-r--r--test/mitmproxy/test_optmanager.py5
4 files changed, 39 insertions, 5 deletions
diff --git a/mitmproxy/optmanager.py b/mitmproxy/optmanager.py
index 3768b52c..5b156841 100644
--- a/mitmproxy/optmanager.py
+++ b/mitmproxy/optmanager.py
@@ -6,6 +6,7 @@ import functools
import weakref
import os
import typing
+import textwrap
import ruamel.yaml
@@ -371,3 +372,22 @@ class OptManager:
)
else:
raise ValueError("Unsupported option type: %s", o.typespec)
+
+
+def dump(opts):
+ """
+ Dumps an annotated file with all options.
+ """
+ # Sort data
+ s = ruamel.yaml.comments.CommentedMap()
+ for k in sorted(opts.keys()):
+ o = opts._options[k]
+ s[k] = o.default
+ if o.help:
+ s.yaml_set_comment_before_after_key(
+ k,
+ before = "\n" + "\n".join(textwrap.wrap(
+ textwrap.dedent(o.help.strip())
+ )),
+ )
+ return ruamel.yaml.round_trip_dump(s)
diff --git a/mitmproxy/tools/cmdline.py b/mitmproxy/tools/cmdline.py
index e789aeab..7b0da34f 100644
--- a/mitmproxy/tools/cmdline.py
+++ b/mitmproxy/tools/cmdline.py
@@ -21,6 +21,11 @@ def common_options(parser, opts):
version=version.VERSION
)
parser.add_argument(
+ '--options',
+ action='store_true',
+ help="Dump all options",
+ )
+ parser.add_argument(
"-q", "--quiet",
action="store_true", dest="quiet",
help="Quiet."
diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py
index 36133555..5c58d995 100644
--- a/mitmproxy/tools/main.py
+++ b/mitmproxy/tools/main.py
@@ -12,6 +12,7 @@ import signal # noqa
from mitmproxy.tools import cmdline # noqa
from mitmproxy import exceptions # noqa
from mitmproxy import options # noqa
+from mitmproxy import optmanager # noqa
from mitmproxy.proxy import config # noqa
from mitmproxy.proxy import server # noqa
from mitmproxy.utils import version_check # noqa
@@ -34,21 +35,24 @@ def assert_utf8_env():
sys.exit(1)
-def process_options(parser, options, args):
+def process_options(parser, opts, args):
if args.version:
print(debug.dump_system_info())
sys.exit(0)
+ if args.options:
+ print(optmanager.dump(opts))
+ sys.exit(0)
if args.quiet:
args.flow_detail = 0
adict = {}
for n in dir(args):
- if n in options:
+ if n in opts:
adict[n] = getattr(args, n)
- options.merge(adict)
+ opts.merge(adict)
- pconf = config.ProxyConfig(options)
- if options.no_server:
+ pconf = config.ProxyConfig(opts)
+ if opts.no_server:
return server.DummyServer(pconf)
else:
try:
diff --git a/test/mitmproxy/test_optmanager.py b/test/mitmproxy/test_optmanager.py
index a38662d5..6729b155 100644
--- a/test/mitmproxy/test_optmanager.py
+++ b/test/mitmproxy/test_optmanager.py
@@ -280,3 +280,8 @@ def test_option():
assert o2 == o
o2.set(5)
assert o2 != o
+
+
+def test_dump():
+ o = options.Options()
+ assert optmanager.dump(o) \ No newline at end of file