Skip to content

Commit ad03a75

Browse files
Improve MultiCLI output
1 parent d05c7d0 commit ad03a75

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Changelog
1414
### 2.6.0 - August 28, 2019
1515
- Improved CLI multiple behaviour with empty defaults
1616
- Improved CLI type output for built-in types
17+
- Improved MultiCLI base documentation
1718

1819
### 2.5.6 - June 20, 2019
1920
- Fixed issue #815: map_params() causes api documentation to lose param type information

examples/cli_object.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ class GIT(object):
99

1010
@hug.object.cli
1111
def push(self, branch="master"):
12+
"""Push the latest to origin"""
1213
return "Pushing {}".format(branch)
1314

1415
@hug.object.cli
1516
def pull(self, branch="master"):
17+
"""Pull in the latest from origin"""
1618
return "Pulling {}".format(branch)
1719

1820

hug/api.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,12 @@ def output_format(self, formatter):
469469
self._output_format = formatter
470470

471471
def __str__(self):
472-
return "{0}\n\nAvailable Commands:{1}\n".format(
473-
self.api.doc or self.api.name, "\n\n\t- " + "\n\t- ".join(self.commands.keys())
474-
)
475-
472+
output = "{0}\n\nAvailable Commands:\n\n".format(self.api.doc or self.api.name)
473+
for command_name, command in self.commands.items():
474+
command_string = " - {}{}".format(command_name, ": " + command.parser.description.replace("\n", " ") if command.parser.description else "")
475+
output += (command_string[:77] + "..." if len(command_string) > 80 else command_string)
476+
output += "\n"
477+
return output
476478

477479
class ModuleSingleton(type):
478480
"""Defines the module level __hug__ singleton"""

0 commit comments

Comments
 (0)