Skip to content

Commit

Permalink
help: if groff is not found, try mandoc
Browse files Browse the repository at this point in the history
This will allow 'help' to work on BSDs, Illumos and Linux
distributions using the mandoc formatter.
  • Loading branch information
Antoine Jacoutot authored and hssyoo committed Nov 8, 2022
1 parent 277e232 commit 172dc0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions awscli/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down

0 comments on commit 172dc0a

Please sign in to comment.