diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2017-03-07 13:16:28 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2017-03-07 13:16:28 +1300 |
commit | 99a6b0dbc1cc68bbcdbae1060a6f75ff4f0e9bf8 (patch) | |
tree | 078444dd0217ef17502e26b0c0af6d6bd4b05df3 /mitmproxy/optmanager.py | |
parent | d13df40753a3e8259ef4d2f25d9cb0c1e8141223 (diff) | |
download | mitmproxy-99a6b0dbc1cc68bbcdbae1060a6f75ff4f0e9bf8.tar.gz mitmproxy-99a6b0dbc1cc68bbcdbae1060a6f75ff4f0e9bf8.tar.bz2 mitmproxy-99a6b0dbc1cc68bbcdbae1060a6f75ff4f0e9bf8.zip |
Add --options that dumps annotated option defaults
Diffstat (limited to 'mitmproxy/optmanager.py')
-rw-r--r-- | mitmproxy/optmanager.py | 20 |
1 files changed, 20 insertions, 0 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) |