diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2017-03-07 19:29:08 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2017-03-07 19:29:08 +1300 |
commit | b0ba76559869053e49b9c11b826a542b4885b49d (patch) | |
tree | 8548869dbc21a05c61ae1a0b6923d881f77be5b2 /mitmproxy/optmanager.py | |
parent | 320d8848abea644965256da651bad8a4a8e92678 (diff) | |
download | mitmproxy-b0ba76559869053e49b9c11b826a542b4885b49d.tar.gz mitmproxy-b0ba76559869053e49b9c11b826a542b4885b49d.tar.bz2 mitmproxy-b0ba76559869053e49b9c11b826a542b4885b49d.zip |
Add type and choices to options dump commets.
Diffstat (limited to 'mitmproxy/optmanager.py')
-rw-r--r-- | mitmproxy/optmanager.py | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/mitmproxy/optmanager.py b/mitmproxy/optmanager.py index f03055eb..8dddd11a 100644 --- a/mitmproxy/optmanager.py +++ b/mitmproxy/optmanager.py @@ -359,8 +359,8 @@ class OptManager: optname, getattr(self, optname) + [optval] ) - else: - raise ValueError("Unsupported option type: %s", o.typespec) + else: # pragma: no cover + raise NotImplementedError("Unsupported option type: %s", o.typespec) def make_parser(self, parser, optname, metavar=None): o = self._options[optname] @@ -421,10 +421,25 @@ def dump(opts): for k in sorted(opts.keys()): o = opts._options[k] s[k] = o.default - s.yaml_set_comment_before_after_key( - k, - before = "\n" + "\n".join(textwrap.wrap( - textwrap.dedent(o.help.strip()) - )), + txt = o.help.strip() + + if o.choices: + txt += " Valid values are %s." % ", ".join(repr(c) for c in o.choices) + else: + if o.typespec in (str, int, bool): + t = o.typespec.__name__ + elif o.typespec == typing.Optional[str]: + t = "optional str" + elif o.typespec == typing.Sequence[str]: + t = "sequence of str" + else: # pragma: no cover + raise NotImplementedError + txt += " Type %s." % t + + txt = "\n".join( + textwrap.wrap( + textwrap.dedent(txt) + ) ) + s.yaml_set_comment_before_after_key(k, before = "\n" + txt) return ruamel.yaml.round_trip_dump(s) |