diff options
| author | Aldo Cortesi <aldo@corte.si> | 2017-04-30 14:20:21 +1200 |
|---|---|---|
| committer | Aldo Cortesi <aldo@corte.si> | 2017-04-30 14:20:21 +1200 |
| commit | ed62bbad1d7b0e7f3f948e2cc1503687edafc811 (patch) | |
| tree | 7b3a8e87693cd807ff78d696ef3e4e5974fc0f7c | |
| parent | 075d452a6d4e9f21ffd7b3293ec9270ee961917a (diff) | |
| download | mitmproxy-ed62bbad1d7b0e7f3f948e2cc1503687edafc811.tar.gz mitmproxy-ed62bbad1d7b0e7f3f948e2cc1503687edafc811.tar.bz2 mitmproxy-ed62bbad1d7b0e7f3f948e2cc1503687edafc811.zip | |
Add help text to --commands output
| -rw-r--r-- | mitmproxy/command.py | 10 | ||||
| -rw-r--r-- | mitmproxy/tools/main.py | 6 | ||||
| -rw-r--r-- | test/mitmproxy/test_command.py | 5 |
3 files changed, 16 insertions, 5 deletions
diff --git a/mitmproxy/command.py b/mitmproxy/command.py index 8bf2794c..337afd76 100644 --- a/mitmproxy/command.py +++ b/mitmproxy/command.py @@ -3,6 +3,7 @@ import typing import shlex import textwrap import functools +import sys from mitmproxy.utils import typecheck from mitmproxy import exceptions @@ -109,6 +110,15 @@ class CommandManager: raise exceptions.CommandError("Invalid command: %s" % cmdstr) return self.call_args(parts[0], parts[1:]) + def dump(self, out=sys.stdout) -> None: + cmds = list(self.commands.values()) + cmds.sort(key=lambda x: x.signature_help()) + for c in cmds: + for hl in (c.help or "").splitlines(): + print("# " + hl, file=out) + print(c.signature_help(), file=out) + print(file=out) + def parsearg(manager: CommandManager, spec: str, argtype: type) -> typing.Any: """ diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py index fefdca5c..9748f3cf 100644 --- a/mitmproxy/tools/main.py +++ b/mitmproxy/tools/main.py @@ -85,11 +85,7 @@ def run(MasterKlass, args, extra=None): # pragma: no cover print(optmanager.dump_defaults(opts)) sys.exit(0) if args.commands: - cmds = [] - for c in master.commands.commands.values(): - cmds.append(c.signature_help()) - for i in sorted(cmds): - print(i) + master.commands.dump() sys.exit(0) opts.set(*args.setoptions) if extra: diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index aef05adc..24d11d37 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -7,6 +7,7 @@ from mitmproxy import proxy from mitmproxy import exceptions from mitmproxy.test import tflow from mitmproxy.test import taddons +import io import pytest @@ -55,6 +56,10 @@ def test_simple(): c.add("empty", a.empty) c.call("empty") + fp = io.StringIO() + c.dump(fp) + assert fp.getvalue() + def test_typename(): assert command.typename(str, True) == "str" |
