Run a shell command, capturing the lines of stdout. The command WILL be parsed in a shell-like fashion. Be careful with quoting when interpolating variables into it. Use shlex.quote() if necessary. suppress_stderr: if False (default), stderr will be sent to the terminal. check_returnco
(cmd: str, suppress_stderr=False, check_returncode=True)
| 54 | return result[0] |
| 55 | |
| 56 | def shell(cmd: str, suppress_stderr=False, check_returncode=True) -> List[str]: |
| 57 | """Run a shell command, capturing the lines of stdout. |
| 58 | |
| 59 | The command WILL be parsed in a shell-like fashion. Be careful with quoting when interpolating variables into it. Use shlex.quote() if necessary. |
| 60 | |
| 61 | suppress_stderr: if False (default), stderr will be sent to the terminal. |
| 62 | check_returncode: if True (default), throw an exception if the return code is nonzero.""" |
| 63 | |
| 64 | handle_stderr = subprocess.PIPE if suppress_stderr else None |
| 65 | |
| 66 | # If check is True, a CalledProcessError will be raised on nonzero exit code. |
| 67 | if ECHO_COMMANDS: |
| 68 | print(f" > {cmd}") |
| 69 | result = subprocess.run(["sh", "-c", cmd], stdout=subprocess.PIPE, stderr=handle_stderr, check=check_returncode) |
| 70 | return result.stdout.decode("utf-8").rstrip().split("\n") |
| 71 | |
| 72 | def prompt_chars(prompt: str, chars: str) -> str: |
| 73 | """Prompt the user with a multiple-choice question.""" |
no test coverage detected