use rawformatter and add epilog

This commit is contained in:
2019-07-26 16:39:01 +02:00
parent 71608ef63f
commit 7917fcabe5
2 changed files with 80 additions and 3 deletions

View File

@ -13,7 +13,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from typing import Union, List, Dict, Tuple, Optional, Any
from argparse import ArgumentParser, Namespace, SUPPRESS, _HelpAction, HelpFormatter
from argparse import ArgumentParser, Namespace, SUPPRESS, _HelpAction, RawDescriptionHelpFormatter
from copy import copy
from gettext import gettext as _
@ -106,7 +106,7 @@ class TiramisuNamespace(Namespace):
self._config.option(true_key, index).value.set(value)
class TiramisuHelpFormatter(HelpFormatter):
class TiramisuHelpFormatter(RawDescriptionHelpFormatter):
def _get_default_metavar_for_optional(self,
action):
ret = super()._get_default_metavar_for_optional(action)
@ -114,7 +114,7 @@ class TiramisuHelpFormatter(HelpFormatter):
ret = ret.rsplit('.', 1)[1]
return ret
class _Section(HelpFormatter._Section):
class _Section(RawDescriptionHelpFormatter._Section):
def format_help(self):
# Remove empty OD
if self.formatter.remove_empty_od and \
@ -272,6 +272,7 @@ class TiramisuCmdlineParser(ArgumentParser):
root=self.root,
remove_empty_od=self.remove_empty_od,
remove_empty_description_od=self.remove_empty_description_od,
epilog=self.epilog,
fullpath=self.fullpath)
namespace_, args_ = new_parser._parse_known_args(args_, namespace)
else:
@ -509,6 +510,7 @@ class TiramisuCmdlineParser(ArgumentParser):
fullpath=self.fullpath,
remove_empty_od=self.remove_empty_od,
remove_empty_description_od=self.remove_empty_description_od,
epilog=self.epilog,
_forhelp=True)
return super(TiramisuCmdlineParser, help_formatter).format_usage(*args, **kwargs)
@ -519,6 +521,7 @@ class TiramisuCmdlineParser(ArgumentParser):
fullpath=self.fullpath,
remove_empty_od=self.remove_empty_od,
remove_empty_description_od=self.remove_empty_description_od,
epilog=self.epilog,
_forhelp=True)
return super(TiramisuCmdlineParser, help_formatter).format_help()