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 /subcmds/help.py | |
parent | e2effe11a57508f04632cca543292d6568572905 (diff) | |
download | git-repo-0888a083ec6a23a75d3e681f08ef242acd862573.tar.gz |
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>
Diffstat (limited to 'subcmds/help.py')
-rw-r--r-- | subcmds/help.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/subcmds/help.py b/subcmds/help.py index 9ba9e706..6a767e6f 100644 --- a/subcmds/help.py +++ b/subcmds/help.py | |||
@@ -14,7 +14,7 @@ | |||
14 | 14 | ||
15 | import re | 15 | import re |
16 | import sys | 16 | import sys |
17 | from formatter import AbstractFormatter, DumbWriter | 17 | import textwrap |
18 | 18 | ||
19 | from subcmds import all_commands | 19 | from subcmds import all_commands |
20 | from color import Coloring | 20 | from color import Coloring |
@@ -84,8 +84,7 @@ Displays detailed usage information about a command. | |||
84 | def __init__(self, gc): | 84 | def __init__(self, gc): |
85 | Coloring.__init__(self, gc, 'help') | 85 | Coloring.__init__(self, gc, 'help') |
86 | self.heading = self.printer('heading', attr='bold') | 86 | self.heading = self.printer('heading', attr='bold') |
87 | 87 | self._first = True | |
88 | self.wrap = AbstractFormatter(DumbWriter()) | ||
89 | 88 | ||
90 | def _PrintSection(self, heading, bodyAttr): | 89 | def _PrintSection(self, heading, bodyAttr): |
91 | try: | 90 | try: |
@@ -95,7 +94,9 @@ Displays detailed usage information about a command. | |||
95 | if body == '' or body is None: | 94 | if body == '' or body is None: |
96 | return | 95 | return |
97 | 96 | ||
98 | self.nl() | 97 | if not self._first: |
98 | self.nl() | ||
99 | self._first = False | ||
99 | 100 | ||
100 | self.heading('%s%s', header_prefix, heading) | 101 | self.heading('%s%s', header_prefix, heading) |
101 | self.nl() | 102 | self.nl() |
@@ -105,7 +106,8 @@ Displays detailed usage information about a command. | |||
105 | body = body.strip() | 106 | body = body.strip() |
106 | body = body.replace('%prog', me) | 107 | body = body.replace('%prog', me) |
107 | 108 | ||
108 | asciidoc_hdr = re.compile(r'^\n?#+ (.+)$') | 109 | # Extract the title, but skip any trailing {#anchors}. |
110 | asciidoc_hdr = re.compile(r'^\n?#+ ([^{]+)(\{#.+\})?$') | ||
109 | for para in body.split("\n\n"): | 111 | for para in body.split("\n\n"): |
110 | if para.startswith(' '): | 112 | if para.startswith(' '): |
111 | self.write('%s', para) | 113 | self.write('%s', para) |
@@ -120,9 +122,12 @@ Displays detailed usage information about a command. | |||
120 | self.nl() | 122 | self.nl() |
121 | continue | 123 | continue |
122 | 124 | ||
123 | self.wrap.add_flowing_data(para) | 125 | lines = textwrap.wrap(para.replace(' ', ' '), width=80, |
124 | self.wrap.end_paragraph(1) | 126 | break_long_words=False, break_on_hyphens=False) |
125 | self.wrap.end_paragraph(0) | 127 | for line in lines: |
128 | self.write('%s', line) | ||
129 | self.nl() | ||
130 | self.nl() | ||
126 | 131 | ||
127 | out = _Out(self.client.globalConfig) | 132 | out = _Out(self.client.globalConfig) |
128 | out._PrintSection('Summary', 'helpSummary') | 133 | out._PrintSection('Summary', 'helpSummary') |