此格式改變一個方法,_fill_text
:
class RawDescriptionHelpFormatter(HelpFormatter):
....
def _fill_text(self, text, width, indent):
return ''.join(indent + line for line in text.splitlines(keepends=True))
此處理包裝爲公司在format_help
方法定義爲text
什麼
def format_help(self):
formatter = self._get_formatter()
# usage
formatter.add_usage(self.usage, self._actions,
self._mutually_exclusive_groups)
# description
formatter.add_text(self.description)
# positionals, optionals and user-defined groups
for action_group in self._action_groups:
formatter.start_section(action_group.title)
formatter.add_text(action_group.description)
formatter.add_arguments(action_group._group_actions)
formatter.end_section()
# epilog
formatter.add_text(self.epilog)
# determine help from format above
return formatter.format_help()
也就是說,description
的group.description
和epilog
。
我能想象創造一個替代格式化子類,只能改變結尾處理(也許一些關鍵字標識)的包裝。但是我會把它作爲讀者的練習。 :)