|
|
|
@ -14,11 +14,12 @@
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
|
|
import optparse
|
|
|
|
|
import sys
|
|
|
|
|
import re
|
|
|
|
|
import textwrap
|
|
|
|
|
import optparse
|
|
|
|
|
|
|
|
|
|
from cl_utils import _toUNICODE
|
|
|
|
|
from cl_lang import lang
|
|
|
|
|
tr = lang()
|
|
|
|
|
tr.setLocalDomain('cl_lib')
|
|
|
|
@ -83,6 +84,55 @@ def make_option(shortOption=None,longOption=None,
|
|
|
|
|
|
|
|
|
|
class ShareHelpFormatter:
|
|
|
|
|
"""Общие методы форматирования help-а"""
|
|
|
|
|
|
|
|
|
|
def format_option(self, option):
|
|
|
|
|
# The help for each option consists of two parts:
|
|
|
|
|
# * the opt strings and metavars
|
|
|
|
|
# eg. ("-x", or "-fFILENAME, --file=FILENAME")
|
|
|
|
|
# * the user-supplied help string
|
|
|
|
|
# eg. ("turn on expert mode", "read data from FILENAME")
|
|
|
|
|
#
|
|
|
|
|
# If possible, we write both of these on the same line:
|
|
|
|
|
# -x turn on expert mode
|
|
|
|
|
#
|
|
|
|
|
# But if the opt string list is too long, we put the help
|
|
|
|
|
# string on a second line, indented to the same column it would
|
|
|
|
|
# start in if it fit on the first line.
|
|
|
|
|
# -fFILENAME, --file=FILENAME
|
|
|
|
|
# read data from FILENAME
|
|
|
|
|
result = []
|
|
|
|
|
opts = self.option_strings[option]
|
|
|
|
|
opt_width = self.help_position - self.current_indent - 2
|
|
|
|
|
if len(opts) > opt_width:
|
|
|
|
|
opts = "%*s%s\n" % (self.current_indent, "", opts)
|
|
|
|
|
indent_first = self.help_position
|
|
|
|
|
else: # start help on same line as opts
|
|
|
|
|
opts = "%*s%-*s " % (self.current_indent, "", opt_width, opts)
|
|
|
|
|
indent_first = 0
|
|
|
|
|
result.append(opts)
|
|
|
|
|
if option.help:
|
|
|
|
|
help_text = self.expand_default(option)
|
|
|
|
|
help_lines = map(lambda x : x.encode('UTF-8'),
|
|
|
|
|
textwrap.wrap(_toUNICODE(help_text),
|
|
|
|
|
self.help_width))
|
|
|
|
|
result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
|
|
|
|
|
result.extend(["%*s%s\n" % (self.help_position, "", line)
|
|
|
|
|
for line in help_lines[1:]])
|
|
|
|
|
elif opts[-1] != "\n":
|
|
|
|
|
result.append("\n")
|
|
|
|
|
return "".join(result)
|
|
|
|
|
|
|
|
|
|
def _format_text(self, text):
|
|
|
|
|
"""
|
|
|
|
|
Format a paragraph of free-form text for inclusion in the
|
|
|
|
|
help output at the current indentation level.
|
|
|
|
|
"""
|
|
|
|
|
text_width = self.width - self.current_indent
|
|
|
|
|
indent = " "*self.current_indent
|
|
|
|
|
return textwrap.fill(_toUNICODE(text),
|
|
|
|
|
text_width,
|
|
|
|
|
initial_indent=indent,
|
|
|
|
|
subsequent_indent=indent).encode('UTF-8')
|
|
|
|
|
|
|
|
|
|
def format_description(self, description):
|
|
|
|
|
if description:
|
|
|
|
|