MCPcopy Index your code
hub / github.com/aws/aws-cli / PosixPagingHelpRenderer

Class PosixPagingHelpRenderer

awscli/help.py:191–232  ·  view source on GitHub ↗

Render help content on a Posix-like system. This includes Linux and MacOS X.

Source from the content-addressed store, hash-verified

189
190
191class PosixPagingHelpRenderer(PagingHelpRenderer):
192 """
193 Render help content on a Posix-like system. This includes
194 Linux and MacOS X.
195 """
196
197 PAGER = 'less -R'
198
199 def _send_output_to_pager(self, output):
200 cmdline = self.get_pager_cmdline()
201 if not self._exists_on_path(cmdline[0]):
202 LOG.debug(
203 f"Pager '{cmdline[0]}' not found in PATH, printing raw help."
204 )
205 self.output_stream.write(output.decode('utf-8') + "\n")
206 self.output_stream.flush()
207 return
208 LOG.debug("Running command: %s", cmdline)
209 with ignore_ctrl_c():
210 # We can't rely on the KeyboardInterrupt from
211 # the CLIDriver being caught because when we
212 # send the output to a pager it will use various
213 # control characters that need to be cleaned
214 # up gracefully. Otherwise if we simply catch
215 # the Ctrl-C and exit, it will likely leave the
216 # users terminals in a bad state and they'll need
217 # to manually run ``reset`` to fix this issue.
218 # Ignoring Ctrl-C solves this issue. It's also
219 # the default behavior of less (you can't ctrl-c
220 # out of a manpage).
221 p = self._popen(cmdline, stdin=PIPE)
222 p.communicate(input=output)
223
224 def _exists_on_path(self, name):
225 # Since we're only dealing with POSIX systems, we can
226 # ignore things like PATHEXT.
227 return any(
228 [
229 os.path.exists(os.path.join(p, name))
230 for p in os.environ.get('PATH', '').split(os.pathsep)
231 ]
232 )
233
234
235class PosixHelpRenderer(PosixPagingHelpRenderer):

Callers 1

get_rendererFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected