mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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>
This commit is contained in:
parent
e2effe11a5
commit
0888a083ec
@ -21,6 +21,7 @@ following DTD:
|
||||
|
||||
```xml
|
||||
<!DOCTYPE manifest [
|
||||
|
||||
<!ELEMENT manifest (notice?,
|
||||
remote*,
|
||||
default?,
|
||||
|
@ -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
|
||||
|
||||
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')
|
||||
|
Loading…
Reference in New Issue
Block a user