From 172dc0a76715e6a2e43a12bc2a7251f9ff10b32b Mon Sep 17 00:00:00 2001 From: Antoine Jacoutot Date: Sun, 4 Jun 2017 11:23:43 +0200 Subject: [PATCH] help: if groff is not found, try mandoc This will allow 'help' to work on BSDs, Illumos and Linux distributions using the mandoc formatter. --- awscli/help.py | 9 ++++++--- tests/unit/test_help.py | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/awscli/help.py b/awscli/help.py index 0ab6328fb4bc..4b3920cb24e1 100644 --- a/awscli/help.py +++ b/awscli/help.py @@ -106,9 +106,12 @@ class PosixHelpRenderer(PagingHelpRenderer): def _convert_doc_content(self, contents): man_contents = publish_string(contents, writer=manpage.Writer()) - if not self._exists_on_path('groff'): - raise ExecutableNotFoundError('groff') - cmdline = ['groff', '-m', 'man', '-T', 'ascii'] + if self._exists_on_path('groff'): + cmdline = ['groff', '-m', 'man', '-T', 'ascii'] + elif self._exists_on_path('mandoc'): + cmdline = ['mandoc', '-T', 'ascii'] + else: + raise ExecutableNotFoundError('groff or mandoc') LOG.debug("Running command: %s", cmdline) p3 = self._popen(cmdline, stdin=PIPE, stdout=PIPE, stderr=PIPE) groff_output = p3.communicate(input=man_contents)[0] diff --git a/tests/unit/test_help.py b/tests/unit/test_help.py index 3861b4601085..012e6844cdb7 100644 --- a/tests/unit/test_help.py +++ b/tests/unit/test_help.py @@ -99,8 +99,8 @@ def test_pager_with_args(self): def test_no_groff_exists(self): renderer = FakePosixHelpRenderer() renderer.exists_on_path['groff'] = False - expected_error = 'Could not find executable named "groff"' - with self.assertRaisesRegex(ExecutableNotFoundError, expected_error): + expected_error = 'Could not find executable named "groff or mandoc"' + with self.assertRaisesRegexp(ExecutableNotFoundError, expected_error): renderer.render('foo') @skip_if_windows('Requires POSIX system.')