diff options
| author | Mike Frysinger <vapier@google.com> | 2021-04-13 20:22:01 -0400 |
|---|---|---|
| committer | Mike Frysinger <vapier@google.com> | 2021-04-14 01:00:51 +0000 |
| commit | 0888a083ec6a23a75d3e681f08ef242acd862573 (patch) | |
| tree | a32a8dd2ffb73cf6c6c756b9ad23e47f76ae45ff | |
| parent | e2effe11a57508f04632cca543292d6568572905 (diff) | |
| download | git-repo-0888a083ec6a23a75d3e681f08ef242acd862573.tar.gz git-repo-0888a083ec6a23a75d3e681f08ef242acd862573.zip | |
help: switch from formatter module to textwrap
Since Python has deprecated the formatter module, switch to the textwrap
module instead for reflowing text. We weren't really using any other
feature anyways.
Verified by diffing the output before & after the change and making sure
it was the same.
Then made a few tweaks to tighten up the output.
Change-Id: I0be1bc2a6661a311b1a4693c80d0f8366320ba55
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/303282
Reviewed-by: Raman Tenneti <rtenneti@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
| -rw-r--r-- | docs/manifest-format.md | 1 | ||||
| -rw-r--r-- | subcmds/help.py | 21 |
2 files changed, 14 insertions, 8 deletions
diff --git a/docs/manifest-format.md b/docs/manifest-format.md index aa1580d95..da83d0dd3 100644 --- a/docs/manifest-format.md +++ b/docs/manifest-format.md @@ -21,6 +21,7 @@ following DTD: ```xml <!DOCTYPE manifest [ + <!ELEMENT manifest (notice?, remote*, default?, diff --git a/subcmds/help.py b/subcmds/help.py index 9ba9e7061..6a767e6fd 100644 --- a/subcmds/help.py +++ b/subcmds/help.py @@ -14,7 +14,7 @@ import re import sys -from formatter import AbstractFormatter, DumbWriter +import textwrap from subcmds import all_commands from color import Coloring @@ -84,8 +84,7 @@ Displays detailed usage information about a command. def __init__(self, gc): Coloring.__init__(self, gc, 'help') self.heading = self.printer('heading', attr='bold') - - self.wrap = AbstractFormatter(DumbWriter()) + self._first = True def _PrintSection(self, heading, bodyAttr): try: @@ -95,7 +94,9 @@ Displays detailed usage information about a command. if body == '' or body is None: return - self.nl() + if not self._first: + self.nl() + self._first = False self.heading('%s%s', header_prefix, heading) self.nl() @@ -105,7 +106,8 @@ Displays detailed usage information about a command. body = body.strip() body = body.replace('%prog', me) - asciidoc_hdr = re.compile(r'^\n?#+ (.+)$') + # Extract the title, but skip any trailing {#anchors}. + asciidoc_hdr = re.compile(r'^\n?#+ ([^{]+)(\{#.+\})?$') for para in body.split("\n\n"): if para.startswith(' '): self.write('%s', para) @@ -120,9 +122,12 @@ Displays detailed usage information about a command. self.nl() continue - self.wrap.add_flowing_data(para) - self.wrap.end_paragraph(1) - self.wrap.end_paragraph(0) + lines = textwrap.wrap(para.replace(' ', ' '), width=80, + break_long_words=False, break_on_hyphens=False) + for line in lines: + self.write('%s', line) + self.nl() + self.nl() out = _Out(self.client.globalConfig) out._PrintSection('Summary', 'helpSummary') |
