Skip to content

Commit

Permalink
feat: strip and truncate doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
whwright committed Mar 25, 2024
1 parent 7f99e34 commit 2bee976
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions click_command_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def _print_tree(command, depth=0, is_last_item=False, is_last_parent=False):
line = prefix * (depth - 1) + tree_item + command.name
doc = command.command.__doc__
if doc:
doc = doc.strip()
doc = doc[:80] + ' ...' if len(doc) > 80 else doc
line += ' - {}'.format(doc)

click.echo(line)
Expand Down
20 changes: 20 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,26 @@ def command_three():
root
├── command-one
└── command-three
"""[1:]

self._assert_correct_output(root, expected_output)

def test_long_docstring(self):
@click.group(name='root')
def root():
pass

@root.command(name='command')
def command():
"""
this is a really long multi line doc string this is a really long multi line doc string
this is a really long multi line doc string this is a really long multi line doc string
"""
pass

expected_output = """
root
└── command - this is a really long multi line doc string this is a really long multi line doc ...
"""[1:]

self._assert_correct_output(root, expected_output)
Expand Down

0 comments on commit 2bee976

Please sign in to comment.