in knack/help.py [0:0]
def _print_groups(self, help_file):
LINE_FORMAT = '{name}{padding}{tags}{separator}{summary}'
indent = 1
self.max_line_len = 0
def _build_tags_string(item):
preview_info = getattr(item, 'preview_info', None)
preview = preview_info.tag if preview_info else ''
experimental_info = getattr(item, 'experimental_info', None)
experimental = experimental_info.tag if experimental_info else ''
deprecate_info = getattr(item, 'deprecate_info', None)
deprecated = deprecate_info.tag if deprecate_info else ''
required = REQUIRED_TAG if getattr(item, 'required', None) else ''
tags = ' '.join([x for x in [str(deprecated), str(preview), str(experimental), required] if x])
tags_len = sum([
len(deprecated),
len(preview),
len(experimental),
len(required),
tags.count(' ')
])
if not tags_len:
tags = ''
return tags, tags_len
def _layout_items(items):
layouts = []
for c in sorted(items, key=lambda h: h.name):
tags, tags_len = _build_tags_string(c)
line_len = _get_line_len(c.name, tags_len)
layout = {
'name': c.name,
'tags': tags,
'separator': FIRST_LINE_PREFIX if c.short_summary else '',
'summary': c.short_summary or '',
'line_len': line_len
}
layout['summary'] = layout['summary'].replace('\n', ' ')
if line_len > self.max_line_len:
self.max_line_len = line_len
layouts.append(layout)
return layouts
def _print_items(layouts):
for layout in layouts:
layout['padding'] = ' ' * _get_padding_len(self.max_line_len, layout)
_print_indent(
LINE_FORMAT.format(**layout),
indent,
_get_hanging_indent(self.max_line_len, indent),
width=self.textwrap_width,
)
_print_indent('')
groups = [c for c in help_file.children if isinstance(c, self.group_help_cls)]
group_layouts = _layout_items(groups)
commands = [c for c in help_file.children if c not in groups]
command_layouts = _layout_items(commands)
if groups:
_print_indent('Subgroups:')
_print_items(group_layouts)
if commands:
_print_indent('Commands:')
_print_items(command_layouts)