summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2013-04-03 10:40:30 +0200
committerMartin Kosek <mkosek@redhat.com>2013-04-03 15:32:13 +0200
commit3f6b3397ed5414be2d43832a63b00b56f43f3ae0 (patch)
treebde0baeb1dde7f2d48acbf464632cd09f48ff33c
parent9d8121d47219504791b8111632f474c32485f9b7 (diff)
downloadfreeipa-3f6b3397ed5414be2d43832a63b00b56f43f3ae0.tar.gz
freeipa-3f6b3397ed5414be2d43832a63b00b56f43f3ae0.tar.xz
freeipa-3f6b3397ed5414be2d43832a63b00b56f43f3ae0.zip
Display full command documentation in online help
ipa <command> -h only showed the summary string, not the full help. Use the full docstring. Add a custom help formatter that disables optparse's reformatting. Test included https://fedorahosted.org/freeipa/ticket/3543
-rw-r--r--ipalib/cli.py18
-rw-r--r--tests/test_cmdline/test_help.py11
2 files changed, 28 insertions, 1 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 5150c9bf0..08a13313c 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -1099,7 +1099,8 @@ class cli(backend.Executioner):
def build_parser(self, cmd):
parser = CLIOptionParser(
usage=' '.join(self.usage_iter(cmd)),
- description=cmd.summary,
+ description=unicode(cmd.doc),
+ formatter=IPAHelpFormatter(),
)
option_groups = {}
for option in cmd.options():
@@ -1258,6 +1259,21 @@ class cli(backend.Executioner):
kw[p.name] = self.Backend.textui.decode(raw)
+class IPAHelpFormatter(optparse.IndentedHelpFormatter):
+ """Formatter suitable for printing IPA command help
+
+ The default help formatter reflows text to fit the terminal, but it
+ ignores line/paragraph breaks.
+ IPA's descriptions already have correct line breaks. This formatter
+ doesn't touch them (save for removing initial/trailing whitespace).
+ """
+ def format_description(self, description):
+ if description:
+ return description.strip()
+ else:
+ return ""
+
+
cli_plugins = (
cli,
textui,
diff --git a/tests/test_cmdline/test_help.py b/tests/test_cmdline/test_help.py
index 1ab3ddc49..4cf633683 100644
--- a/tests/test_cmdline/test_help.py
+++ b/tests/test_cmdline/test_help.py
@@ -128,3 +128,14 @@ def test_ambiguous_command_or_topic():
assert h_ctx.stderr == ''
assert h_ctx.stdout != help_ctx.stdout
+
+def test_multiline_description():
+ """Test that all of a multi-line command description appears in output
+ """
+ # This assumes trust_add has multiline doc. Ensure it is so.
+ assert '\n\n' in unicode(api.Command.trust_add.doc).strip()
+
+ with CLITestContext(exception=SystemExit) as help_ctx:
+ return_value = api.Backend.cli.run(['trust-add', '-h'])
+
+ assert unicode(api.Command.trust_add.doc).strip() in help_ctx.stdout