(self, action)
| 521 | return self._fill_text(text, text_width, indent) + '\n\n' |
| 522 | |
| 523 | def _format_action(self, action): |
| 524 | # determine the required width and the entry label |
| 525 | help_position = min(self._action_max_length + 2, |
| 526 | self._max_help_position) |
| 527 | help_width = max(self._width - help_position, 11) |
| 528 | action_width = help_position - self._current_indent - 2 |
| 529 | action_header = self._format_action_invocation(action) |
| 530 | action_header_no_color = self._decolor(action_header) |
| 531 | |
| 532 | # no help; start on same line and add a final newline |
| 533 | if not action.help: |
| 534 | tup = self._current_indent, '', action_header |
| 535 | action_header = '%*s%s\n' % tup |
| 536 | |
| 537 | # short action name; start on the same line and pad two spaces |
| 538 | elif len(action_header_no_color) <= action_width: |
| 539 | # calculate widths without color codes |
| 540 | action_header_color = action_header |
| 541 | tup = self._current_indent, '', action_width, action_header_no_color |
| 542 | action_header = '%*s%-*s ' % tup |
| 543 | # swap in the colored header |
| 544 | action_header = action_header.replace( |
| 545 | action_header_no_color, action_header_color |
| 546 | ) |
| 547 | indent_first = 0 |
| 548 | |
| 549 | # long action name; start on the next line |
| 550 | else: |
| 551 | tup = self._current_indent, '', action_header |
| 552 | action_header = '%*s%s\n' % tup |
| 553 | indent_first = help_position |
| 554 | |
| 555 | # collect the pieces of the action help |
| 556 | parts = [action_header] |
| 557 | |
| 558 | # if there was help for the action, add lines of help text |
| 559 | if action.help and action.help.strip(): |
| 560 | help_text = self._expand_help(action) |
| 561 | if help_text: |
| 562 | help_lines = self._split_lines(help_text, help_width) |
| 563 | parts.append('%*s%s\n' % (indent_first, '', help_lines[0])) |
| 564 | for line in help_lines[1:]: |
| 565 | parts.append('%*s%s\n' % (help_position, '', line)) |
| 566 | |
| 567 | # or add a newline if the description doesn't end with one |
| 568 | elif not action_header.endswith('\n'): |
| 569 | parts.append('\n') |
| 570 | |
| 571 | # if there are any sub-actions, add their help as well |
| 572 | for subaction in self._iter_indented_subactions(action): |
| 573 | parts.append(self._format_action(subaction)) |
| 574 | |
| 575 | # return a single string |
| 576 | return self._join_parts(parts) |
| 577 | |
| 578 | def _format_action_invocation(self, action): |
| 579 | t = self._theme |
nothing calls this directly
no test coverage detected