Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:41

0001 import argparse as _argparse
0002 import textwrap as _textwrap
0003 
0004 # argparse's formatters remove newlines from comand descriptions, so we define a new one
0005 class HelpFormatterRespectNewlines(_argparse.HelpFormatter):
0006     """Help message formatter which retains line breaks in argument descriptions.
0007 
0008     Only the name of this class is considered a public API. All the methods
0009     provided by the class are considered an implementation detail.
0010     """
0011 
0012     def _split_lines(self, text, width):
0013         lines = []
0014         for line in text.splitlines():
0015           line = self._whitespace_matcher.sub(' ', line).strip()
0016           lines.extend( _textwrap.wrap(line, width) )
0017         return lines
0018 
0019 # argparse's formatters are not really able to discover the terminale size, so we override them
0020 def FixedWidthFormatter(formatter, width):
0021   """Adaptor for argparse formatters using an explicit fixed width
0022   """
0023   def f(*args, **keywords):
0024     # add or replace the "width" parameter
0025     keywords['width'] = width
0026     return formatter(*args, **keywords)
0027 
0028   return f
0029