Skip to content

Commit 2bee976

Browse files
committed
feat: strip and truncate doc strings
1 parent 7f99e34 commit 2bee976

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

click_command_tree.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def _print_tree(command, depth=0, is_last_item=False, is_last_parent=False):
4747
line = prefix * (depth - 1) + tree_item + command.name
4848
doc = command.command.__doc__
4949
if doc:
50+
doc = doc.strip()
51+
doc = doc[:80] + ' ...' if len(doc) > 80 else doc
5052
line += ' - {}'.format(doc)
5153

5254
click.echo(line)

tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,26 @@ def command_three():
191191
root
192192
├── command-one
193193
└── command-three
194+
"""[1:]
195+
196+
self._assert_correct_output(root, expected_output)
197+
198+
def test_long_docstring(self):
199+
@click.group(name='root')
200+
def root():
201+
pass
202+
203+
@root.command(name='command')
204+
def command():
205+
"""
206+
this is a really long multi line doc string this is a really long multi line doc string
207+
this is a really long multi line doc string this is a really long multi line doc string
208+
"""
209+
pass
210+
211+
expected_output = """
212+
root
213+
└── command - this is a really long multi line doc string this is a really long multi line doc ...
194214
"""[1:]
195215

196216
self._assert_correct_output(root, expected_output)

0 commit comments

Comments
 (0)