summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2021-04-13 20:22:01 -0400
committerMike Frysinger <vapier@google.com>2021-04-14 01:00:51 +0000
commit0888a083ec6a23a75d3e681f08ef242acd862573 (patch)
treea32a8dd2ffb73cf6c6c756b9ad23e47f76ae45ff
parente2effe11a57508f04632cca543292d6568572905 (diff)
downloadgit-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>
-rw-r--r--docs/manifest-format.md1
-rw-r--r--subcmds/help.py21
2 files changed, 14 insertions, 8 deletions
diff --git a/docs/manifest-format.md b/docs/manifest-format.md
index aa1580d9..da83d0dd 100644
--- a/docs/manifest-format.md
+++ b/docs/manifest-format.md
@@ -21,6 +21,7 @@ following DTD:
21 21
22```xml 22```xml
23<!DOCTYPE manifest [ 23<!DOCTYPE manifest [
24
24 <!ELEMENT manifest (notice?, 25 <!ELEMENT manifest (notice?,
25 remote*, 26 remote*,
26 default?, 27 default?,
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
15import re 15import re
16import sys 16import sys
17from formatter import AbstractFormatter, DumbWriter 17import textwrap
18 18
19from subcmds import all_commands 19from subcmds import all_commands
20from color import Coloring 20from 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')