peltak.core.shell
¶
- class peltak.core.shell.ExecResult(command, return_code, stdout, stderr, succeeded, failed)[source]¶
Encapsulates a
shell.run
result.- succeeded¶
True if command was successful (return_code was 0 or the one that was expected).
- Type
- peltak.core.shell.fmt(msg, *args, **kw)[source]¶
Generate shell color opcodes from a pretty coloring syntax.
- Return type
- peltak.core.shell.highlight(code, fmt)[source]¶
Highlight a given code snippet for printing in the terminal.
Assumes 256 color terminal.
- Return type
- peltak.core.shell.run(cmd, capture=False, shell=True, env=None, exit_on_error=None, never_pretend=False)[source]¶
Run a shell command.
- Parameters
cmd (str) – The shell command to execute.
shell (bool) – Same as in
subprocess.Popen
.capture (bool) – If set to True, it will capture the standard input/error instead of just piping it to the caller stdout/stderr.
env (dict[str, str]) – The subprocess environment variables.
exit_on_error (bool) – If set to True, on failure it will call
sys.exit
with the return code for the executed command.never_pretend (bool) – If set to True the command will always be executed, even if context.get(‘pretend’) is set to True. If set to False or not given, if the
pretend
context value is True, this function will only print the command it would execute and then return a fake result.
- Returns
The execution result containing the return code and output (if capture was set to True).
- Return type