|
1 | 1 | from __future__ import absolute_import |
2 | 2 |
|
3 | | -import argparse |
4 | 3 | import cStringIO |
5 | 4 | import fnmatch |
6 | 5 | import os |
@@ -693,60 +692,3 @@ def __str__(self): |
693 | 692 | return "{0:0>2}.{1:0>2}.{2:0>2}".format(self.hours,self.mins,self.secs) |
694 | 693 | else: |
695 | 694 | return "{0:0>2}.{1:0>2}".format(self.mins,self.secs) |
696 | | - |
697 | | - |
698 | | -class Formatter(argparse.RawTextHelpFormatter): |
699 | | - """FlexiFormatter which respects new line formatting and wraps the rest |
700 | | -
|
701 | | - Example: |
702 | | - >>> parser = argparse.ArgumentParser(formatter_class=FlexiFormatter) |
703 | | - >>> parser.add_argument('a',help='''\ |
704 | | - ... This argument's help text will have this first long line\ |
705 | | - ... wrapped to fit the target window size so that your text\ |
706 | | - ... remains flexible. |
707 | | - ... |
708 | | - ... 1. This option list |
709 | | - ... 2. is still persisted |
710 | | - ... 3. and the option strings get wrapped like this\ |
711 | | - ... with an indent for readability. |
712 | | - ... |
713 | | - ... You must use backslashes at the end of lines to indicate that\ |
714 | | - ... you want the text to wrap instead of preserving the newline. |
715 | | - ... ''') |
716 | | -
|
717 | | - Only the name of this class is considered a public API. All the methods |
718 | | - provided by the class are considered an implementation detail. |
719 | | - """ |
720 | | - |
721 | | - @classmethod |
722 | | - def new(cls, **options): |
723 | | - return lambda prog: Formatter(prog, **options) |
724 | | - |
725 | | - def _split_lines(self, text, width): |
726 | | - lines = list() |
727 | | - main_indent = len(re.match(r'( *)',text).group(1)) |
728 | | - # Wrap each line individually to allow for partial formatting |
729 | | - for line in text.splitlines(): |
730 | | - |
731 | | - # Get this line's indent and figure out what indent to use |
732 | | - # if the line wraps. Account for lists of small variety. |
733 | | - indent = len(re.match(r'( *)',line).group(1)) |
734 | | - list_match = re.match(r'( *)(([*-+>]+|\w+\)|\w+\.) +)',line) |
735 | | - if(list_match): |
736 | | - sub_indent = indent + len(list_match.group(2)) |
737 | | - else: |
738 | | - sub_indent = indent |
739 | | - |
740 | | - # Textwrap will do all the hard work for us |
741 | | - line = self._whitespace_matcher.sub(' ', line).strip() |
742 | | - new_lines = textwrap.wrap( |
743 | | - text=line, |
744 | | - width=width, |
745 | | - initial_indent=' '*(indent-main_indent), |
746 | | - subsequent_indent=' '*(sub_indent-main_indent), |
747 | | - ) |
748 | | - |
749 | | - # Blank lines get eaten by textwrap, put it back with [' '] |
750 | | - lines.extend(new_lines or [' ']) |
751 | | - |
752 | | - return lines |
0 commit comments