Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/next-release/enhancement-docs-15168.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "enhancement",
"category": "docs",
"description": "Fixes `#6918 <https://github.com/aws/aws-cli/issues/6918>`__ and `#7400 <https://github.com/aws/aws-cli/issues/7400>`__. The CLI falls back on mandoc if groff isn't available."
}
13 changes: 8 additions & 5 deletions awscli/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,16 @@ 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]
return groff_output
output = p3.communicate(input=man_contents)[0]
return output

def _send_output_to_pager(self, output):
cmdline = self.get_pager_cmdline()
Expand Down
16 changes: 14 additions & 2 deletions tests/unit/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,25 @@ def test_pager_with_args(self):
pager_cmd.split())

@skip_if_windows('Requires posix system.')
def test_no_groff_exists(self):
def test_no_groff_or_mandoc_exists(self):
renderer = FakePosixHelpRenderer()
renderer.exists_on_path['groff'] = False
expected_error = 'Could not find executable named "groff"'
renderer.exists_on_path['mandoc'] = False
expected_error = 'Could not find executable named "groff or mandoc"'
with self.assertRaisesRegex(ExecutableNotFoundError, expected_error):
renderer.render('foo')

@skip_if_windows('Requires POSIX system.')
def test_renderer_falls_back_to_mandoc(self):
stdout = six.StringIO()
renderer = FakePosixHelpRenderer(output_stream=stdout)

renderer.exists_on_path['groff'] = False
renderer.exists_on_path['mandoc'] = True
renderer.mock_popen.communicate.return_value = (b'foo', '')
renderer.render('foo')
self.assertEqual(stdout.getvalue(), 'foo\n')

@skip_if_windows('Requires POSIX system.')
def test_no_pager_exists(self):
fake_pager = 'foobar'
Expand Down