(self, action)
| 544 | return text |
| 545 | |
| 546 | def _format_action(self, action): |
| 547 | # determine the required width and the entry label |
| 548 | help_position = min(self._action_max_length + 2, |
| 549 | self._max_help_position) |
| 550 | help_width = max(self._width - help_position, 11) |
| 551 | action_width = help_position - self._current_indent - 2 |
| 552 | action_header = self._format_action_invocation(action) |
| 553 | action_header_no_color = self._decolor(action_header) |
| 554 | |
| 555 | # no help; start on same line and add a final newline |
| 556 | if not action.help: |
| 557 | tup = self._current_indent, '', action_header |
| 558 | action_header = '%*s%s\n' % tup |
| 559 | |
| 560 | # short action name; start on the same line and pad two spaces |
| 561 | elif len(action_header_no_color) <= action_width: |
| 562 | # calculate widths without color codes |
| 563 | action_header_color = action_header |
| 564 | tup = self._current_indent, '', action_width, action_header_no_color |
| 565 | action_header = '%*s%-*s ' % tup |
| 566 | # swap in the colored header |
| 567 | action_header = action_header.replace( |
| 568 | action_header_no_color, action_header_color |
| 569 | ) |
| 570 | indent_first = 0 |
| 571 | |
| 572 | # long action name; start on the next line |
| 573 | else: |
| 574 | tup = self._current_indent, '', action_header |
| 575 | action_header = '%*s%s\n' % tup |
| 576 | indent_first = help_position |
| 577 | |
| 578 | # collect the pieces of the action help |
| 579 | parts = [action_header] |
| 580 | |
| 581 | # if there was help for the action, add lines of help text |
| 582 | if action.help and action.help.strip(): |
| 583 | help_text = self._expand_help(action) |
| 584 | if help_text: |
| 585 | help_lines = self._split_lines(help_text, help_width) |
| 586 | parts.append('%*s%s\n' % (indent_first, '', help_lines[0])) |
| 587 | for line in help_lines[1:]: |
| 588 | parts.append('%*s%s\n' % (help_position, '', line)) |
| 589 | |
| 590 | # or add a newline if the description doesn't end with one |
| 591 | elif not action_header.endswith('\n'): |
| 592 | parts.append('\n') |
| 593 | |
| 594 | # if there are any sub-actions, add their help as well |
| 595 | for subaction in self._iter_indented_subactions(action): |
| 596 | parts.append(self._format_action(subaction)) |
| 597 | |
| 598 | # return a single string |
| 599 | return self._join_parts(parts) |
| 600 | |
| 601 | def _format_action_invocation(self, action): |
| 602 | t = self._theme |
nothing calls this directly
no test coverage detected