Skip to content

Commit f70d55b

Browse files
committed
Merge branch 'master' into alert_printer
2 parents b918b22 + 3c51b9f commit f70d55b

File tree

4 files changed

+38
-31
lines changed

4 files changed

+38
-31
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ applications. It provides a simple API which is an extension of Python's built-
1414
of cmd to make your life easier and eliminates much of the boilerplate code which would be necessary
1515
when using cmd.
1616

17-
[![Screenshot](cmd2.png)](https://github.com/python-cmd2/cmd2/blob/master/cmd2.png)
18-
17+
Click on image below to watch a short video demonstrating the capabilities of cmd2:
18+
[![Screenshot](cmd2.png)](https://youtu.be/DDU_JH6cFsA)
1919

2020
Main Features
2121
-------------

cmd2/cmd2.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,13 +2449,17 @@ def _print_topics(self, header: str, cmds: List[str], verbose: bool) -> None:
24492449
doc_block = []
24502450
found_first = False
24512451
for doc_line in doc.splitlines():
2452-
str(doc_line).strip()
2453-
if len(doc_line.strip()) > 0:
2454-
doc_block.append(doc_line.strip())
2455-
found_first = True
2456-
else:
2452+
stripped_line = doc_line.strip()
2453+
2454+
# Don't include :param type lines
2455+
if stripped_line.startswith(':'):
24572456
if found_first:
24582457
break
2458+
elif stripped_line:
2459+
doc_block.append(stripped_line)
2460+
found_first = True
2461+
elif found_first:
2462+
break
24592463

24602464
for doc_line in doc_block:
24612465
self.stdout.write('{: <{col_width}}{doc}\n'.format(command,
@@ -2682,9 +2686,11 @@ def do_py(self, arg: str) -> bool:
26822686
Non-python commands can be issued with ``pyscript_name("your command")``.
26832687
Run python code from external script files with ``run("script.py")``
26842688
"""
2685-
from .pyscript_bridge import PyscriptBridge
2689+
from .pyscript_bridge import PyscriptBridge, CommandResult
26862690
if self._in_py:
2687-
self.perror("Recursively entering interactive Python consoles is not allowed.", traceback_war=False)
2691+
err = "Recursively entering interactive Python consoles is not allowed."
2692+
self.perror(err, traceback_war=False)
2693+
self._last_result = CommandResult('', err)
26882694
return False
26892695
self._in_py = True
26902696

tests/test_cmd2.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ def test_base_help_verbose(base_app):
4646
expected = normalize(BASE_HELP_VERBOSE)
4747
assert out == expected
4848

49+
# Make sure :param type lines are filtered out of help summary
50+
help_doc = base_app.do_help.__func__.__doc__
51+
help_doc += "\n:param fake param"
52+
base_app.do_help.__func__.__doc__ = help_doc
53+
4954
out = run_cmd(base_app, 'help --verbose')
5055
assert out == expected
5156

@@ -215,13 +220,13 @@ def test_base_run_pyscript(base_app, capsys, request):
215220
out, err = capsys.readouterr()
216221
assert out == expected
217222

218-
def test_recursive_pyscript_not_allowed(base_app, capsys, request):
223+
def test_recursive_pyscript_not_allowed(base_app, request):
219224
test_dir = os.path.dirname(request.module.__file__)
220225
python_script = os.path.join(test_dir, 'scripts', 'recursive.py')
221-
expected = 'ERROR: Recursively entering interactive Python consoles is not allowed.\n'
226+
expected = 'Recursively entering interactive Python consoles is not allowed.'
222227

223228
run_cmd(base_app, "pyscript {}".format(python_script))
224-
out, err = capsys.readouterr()
229+
err = base_app._last_result.stderr
225230
assert err == expected
226231

227232
def test_pyscript_with_nonexist_file(base_app, capsys):

tests/test_pyscript.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _do_media_movies(self, args) -> None:
2020
if not args.command:
2121
self.do_help(['media movies'])
2222
else:
23-
print('media movies ' + str(args.__dict__))
23+
self.poutput('media movies ' + str(args.__dict__))
2424

2525
def _do_media_shows(self, args) -> None:
2626
if not args.command:
@@ -29,7 +29,7 @@ def _do_media_shows(self, args) -> None:
2929
if not args.command:
3030
self.do_help(['media shows'])
3131
else:
32-
print('media shows ' + str(args.__dict__))
32+
self.poutput('media shows ' + str(args.__dict__))
3333

3434
media_parser = argparse_completer.ACArgumentParser(prog='media')
3535

@@ -84,7 +84,7 @@ def do_media(self, args):
8484

8585
@with_argparser(foo_parser)
8686
def do_foo(self, args):
87-
print('foo ' + str(args.__dict__))
87+
self.poutput('foo ' + str(args.__dict__))
8888
if self._in_py:
8989
FooResult = namedtuple_with_defaults('FooResult',
9090
['counter', 'trueval', 'constval',
@@ -110,7 +110,7 @@ def do_bar(self, args):
110110
out += '{'
111111
for key in keys:
112112
out += "'{}':'{}'".format(key, arg_dict[key])
113-
print(out)
113+
self.poutput(out)
114114

115115

116116
@pytest.fixture
@@ -126,7 +126,7 @@ def __init__(self):
126126
self.pyscript_name = 'custom'
127127

128128
def do_echo(self, out):
129-
print(out)
129+
self.poutput(out)
130130

131131

132132
@pytest.fixture
@@ -140,7 +140,7 @@ def ps_echo():
140140
('help', 'help.py'),
141141
('help media', 'help_media.py'),
142142
])
143-
def test_pyscript_help(ps_app, capsys, request, command, pyscript_file):
143+
def test_pyscript_help(ps_app, request, command, pyscript_file):
144144
test_dir = os.path.dirname(request.module.__file__)
145145
python_script = os.path.join(test_dir, 'pyscript', pyscript_file)
146146
expected = run_cmd(ps_app, command)
@@ -169,16 +169,14 @@ def test_pyscript_help(ps_app, capsys, request, command, pyscript_file):
169169
('foo 11 22 33 44 55 66 -ccc', 'foo3.py'),
170170
('bar 11 22', 'bar1.py'),
171171
])
172-
def test_pyscript_out(ps_app, capsys, request, command, pyscript_file):
172+
def test_pyscript_out(ps_app, request, command, pyscript_file):
173173
test_dir = os.path.dirname(request.module.__file__)
174174
python_script = os.path.join(test_dir, 'pyscript', pyscript_file)
175-
run_cmd(ps_app, command)
176-
expected, _ = capsys.readouterr()
175+
expected = run_cmd(ps_app, command)
176+
assert expected
177177

178-
assert len(expected) > 0
179-
run_cmd(ps_app, 'pyscript {}'.format(python_script))
180-
out, _ = capsys.readouterr()
181-
assert len(out) > 0
178+
out = run_cmd(ps_app, 'pyscript {}'.format(python_script))
179+
assert out
182180
assert out == expected
183181

184182

@@ -227,14 +225,12 @@ def test_pyscript_dir(ps_app, capsys, request, expected, pyscript_file):
227225
assert out == expected
228226

229227

230-
def test_pyscript_custom_name(ps_echo, capsys, request):
228+
def test_pyscript_custom_name(ps_echo, request):
231229
message = 'blah!'
232230

233231
test_dir = os.path.dirname(request.module.__file__)
234232
python_script = os.path.join(test_dir, 'pyscript', 'custom_echo.py')
235233

236-
run_cmd(ps_echo, 'pyscript {}'.format(python_script))
237-
expected, _ = capsys.readouterr()
238-
assert len(expected) > 0
239-
expected = expected.splitlines()
240-
assert message == expected[0]
234+
out = run_cmd(ps_echo, 'pyscript {}'.format(python_script))
235+
assert out
236+
assert message == out[0]

0 commit comments

Comments
 (0)