Skip to content

Commit 0d853ef

Browse files
Use __str__ as consistent way to get access to CLI command level documentation
1 parent ad03a75 commit 0d853ef

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

hug/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def output_format(self, formatter):
471471
def __str__(self):
472472
output = "{0}\n\nAvailable Commands:\n\n".format(self.api.doc or self.api.name)
473473
for command_name, command in self.commands.items():
474-
command_string = " - {}{}".format(command_name, ": " + command.parser.description.replace("\n", " ") if command.parser.description else "")
474+
command_string = " - {}{}".format(command_name, ": " + str(command).replace("\n", " ") if str(command) else "")
475475
output += (command_string[:77] + "..." if len(command_string) > 80 else command_string)
476476
output += "\n"
477477
return output

hug/interface.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,9 @@ def output(self, data, context):
565565
sys.stdout.buffer.write(b"\n")
566566
return data
567567

568+
def __str__(self):
569+
return self.parser.description or ""
570+
568571
def __call__(self):
569572
"""Calls the wrapped function through the lens of a CLI ran command"""
570573
context = self.api.context_factory(api=self.api, argparse=self.parser, interface=self)

0 commit comments

Comments
 (0)