diff --git a/trh_nagioslib.py b/trh_nagioslib.py index d9f4d4083023678c1fab05075b632ce45870acd3..dbb87e3060dde0065d60ba413510d1b492815119 100644 --- a/trh_nagioslib.py +++ b/trh_nagioslib.py @@ -13,6 +13,8 @@ import re import collections import netsnmp import subprocess +import optparse +import textwrap # Cache of mappings from short names to fully qualified names. @@ -251,3 +253,21 @@ def nagios_report(statuses): message = "UNKNOWN: No status report\n" return max_level, message + + + +class NoReflowHelpFormatter(optparse.IndentedHelpFormatter): + """A HelpFormatter for optparse that does not re-wrap/reflow text. + + Intended for command descriptions that are already properly + pre-formatted. + """ + def format_description(self, description): + if not description: + return "" + desc_width = min(70, self.width - self.current_indent) + indent = " " * self.current_indent + summary,body = (description.strip().split("\n", 1) + [""])[:2] + body = textwrap.dedent(body) + description = summary + "\n" + body + "\n" + return description