Fix crash when no commands are available

This commit is contained in:
Joakim Soderlund 2017-10-14 15:30:15 +02:00
parent 6c0dfd2263
commit 262038e95d
2 changed files with 10 additions and 0 deletions

View file

@ -93,6 +93,9 @@ class RootCommand(Command):
'Fimfarchive, ensuring that history is preseved.\n\n',
]
if not self.commands:
return ''.join(text).strip()
commands = sorted(cmd for cmd in self.commands.keys())
adjust = max(len(cmd) for cmd in commands) + 2

View file

@ -108,6 +108,13 @@ class TestRootCommanad():
assert "failure Command that returns 1." in doc
assert "truncated documentation line" not in doc
def test_root_usage_without_commands(self, root):
"""
Tests usage contains text when no commands are available.
"""
type(root).commands = dict()
assert root.usage.strip()
def test_root_call_without_args(self, root, success, failure):
"""
Tests `SystemExit` is raised if called without arguments.