summaryrefslogtreecommitdiffstats
path: root/ipalib/plugable.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2012-11-06 11:05:41 -0500
committerRob Crittenden <rcritten@redhat.com>2013-02-18 13:07:16 -0500
commit5f5b4c3e5eec96821411685c7d9a80d85c15af07 (patch)
tree1c518745bf4aa199f3311fd94c3409014abbab09 /ipalib/plugable.py
parentd73dd4b6839867390fdf439d71a7f77bdc352acc (diff)
downloadfreeipa-5f5b4c3e5eec96821411685c7d9a80d85c15af07.tar.gz
freeipa-5f5b4c3e5eec96821411685c7d9a80d85c15af07.tar.xz
freeipa-5f5b4c3e5eec96821411685c7d9a80d85c15af07.zip
Improve `ipa --help` output
Fix the usage string to match actual usage. Add command description. Put information about `ipa help topics` etc. to the epilog, instead of using empty option groups. Use a custom formatter to preserve newlines. Add the -h/--help option manually to ensure consistent case (capital S). Part of the effort for https://fedorahosted.org/freeipa/ticket/3060
Diffstat (limited to 'ipalib/plugable.py')
-rw-r--r--ipalib/plugable.py37
1 files changed, 30 insertions, 7 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index f3d185e14..461497954 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -34,6 +34,8 @@ from os import path
import subprocess
import optparse
import errors
+import textwrap
+
from config import Env
import util
import text
@@ -519,8 +521,23 @@ class API(DictProxy):
Add global options to an optparse.OptionParser instance.
"""
if parser is None:
- parser = optparse.OptionParser()
+ parser = optparse.OptionParser(
+ add_help_option=False,
+ formatter=IPAHelpFormatter(),
+ usage='%prog [global-options] COMMAND [command-options]',
+ description='Manage an IPA domain',
+ epilog='\n'.join([
+ 'See "ipa help topics" for available help topics.',
+ 'See "ipa help <TOPIC>" for more information on a '
+ 'specific topic.',
+ 'See "ipa help commands" for the full list of commands.',
+ 'See "ipa help <COMMAND>" for more information on a '
+ 'specific command.',
+ ]))
parser.disable_interspersed_args()
+ parser.add_option("-h", "--help", action="help",
+ help='Show this help message and exit')
+
parser.add_option('-e', dest='env', metavar='KEY=VAL', action='append',
help='Set environment variable KEY to VAL',
)
@@ -548,12 +565,6 @@ class API(DictProxy):
dest='fallback',
help='Only use the server configured in /etc/ipa/default.conf'
)
- topics = optparse.OptionGroup(parser, "Available help topics",
- "ipa help topics")
- cmds = optparse.OptionGroup(parser, "Available commands",
- "ipa help commands")
- parser.add_option_group(topics)
- parser.add_option_group(cmds)
return parser
@@ -730,3 +741,15 @@ class API(DictProxy):
object.__setattr__(self, 'plugins',
tuple(PluginInfo(p) for p in plugins.itervalues())
)
+
+
+class IPAHelpFormatter(optparse.IndentedHelpFormatter):
+ def format_epilog(self, text):
+ text_width = self.width - self.current_indent
+ indent = " " * self.current_indent
+ lines = text.splitlines()
+ result = '\n'.join(
+ textwrap.fill(line, text_width, initial_indent=indent,
+ subsequent_indent=indent)
+ for line in lines)
+ return '\n%s\n' % result