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
|
```xml
|
||||||
<!DOCTYPE manifest [
|
<!DOCTYPE manifest [
|
||||||
|
|
||||||
<!ELEMENT manifest (notice?,
|
<!ELEMENT manifest (notice?,
|
||||||
remote*,
|
remote*,
|
||||||
default?,
|
default?,
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from formatter import AbstractFormatter, DumbWriter
|
import textwrap
|
||||||
|
|
||||||
from subcmds import all_commands
|
from subcmds import all_commands
|
||||||
from color import Coloring
|
from color import Coloring
|
||||||
@ -84,8 +84,7 @@ Displays detailed usage information about a command.
|
|||||||
def __init__(self, gc):
|
def __init__(self, gc):
|
||||||
Coloring.__init__(self, gc, 'help')
|
Coloring.__init__(self, gc, 'help')
|
||||||
self.heading = self.printer('heading', attr='bold')
|
self.heading = self.printer('heading', attr='bold')
|
||||||
|
self._first = True
|
||||||
self.wrap = AbstractFormatter(DumbWriter())
|
|
||||||
|
|
||||||
def _PrintSection(self, heading, bodyAttr):
|
def _PrintSection(self, heading, bodyAttr):
|
||||||
try:
|
try:
|
||||||
@ -95,7 +94,9 @@ Displays detailed usage information about a command.
|
|||||||
if body == '' or body is None:
|
if body == '' or body is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self._first:
|
||||||
self.nl()
|
self.nl()
|
||||||
|
self._first = False
|
||||||
|
|
||||||
self.heading('%s%s', header_prefix, heading)
|
self.heading('%s%s', header_prefix, heading)
|
||||||
self.nl()
|
self.nl()
|
||||||
@ -105,7 +106,8 @@ Displays detailed usage information about a command.
|
|||||||
body = body.strip()
|
body = body.strip()
|
||||||
body = body.replace('%prog', me)
|
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"):
|
for para in body.split("\n\n"):
|
||||||
if para.startswith(' '):
|
if para.startswith(' '):
|
||||||
self.write('%s', para)
|
self.write('%s', para)
|
||||||
@ -120,9 +122,12 @@ Displays detailed usage information about a command.
|
|||||||
self.nl()
|
self.nl()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.wrap.add_flowing_data(para)
|
lines = textwrap.wrap(para.replace(' ', ' '), width=80,
|
||||||
self.wrap.end_paragraph(1)
|
break_long_words=False, break_on_hyphens=False)
|
||||||
self.wrap.end_paragraph(0)
|
for line in lines:
|
||||||
|
self.write('%s', line)
|
||||||
|
self.nl()
|
||||||
|
self.nl()
|
||||||
|
|
||||||
out = _Out(self.client.globalConfig)
|
out = _Out(self.client.globalConfig)
|
||||||
out._PrintSection('Summary', 'helpSummary')
|
out._PrintSection('Summary', 'helpSummary')
|
||||||
|
Loading…
Reference in New Issue
Block a user