运行命令,仅在失败时打印其输出。
项目描述
failprint
运行命令,仅在失败时打印其输出。
厌倦了在程序的 quiet
选项中寻找以减轻 make check
或 make lint
命令输出的繁琐工作吗?
厌倦了发现标准输出和错误在某些情况下混合在一起了吗?
只需通过 failprint
运行您的命令。如果成功,则不打印任何内容。如果失败,则打印标准错误。还有其他配置亮点 :wink
示例
您不希望在命令成功时看到输出。
任务运行器 duty
使用 failprint
,允许您用最小化和美观的输出在 Python 中定义任务并运行它们
要求
failprint 需要 Python 3.8 或更高版本。
要安装Python 3.8,我建议使用pyenv
。
# install pyenv
git clone https://github.com/pyenv/pyenv ~/.pyenv
# setup pyenv (you should also put these three lines in .bashrc or similar)
export PATH="${HOME}/.pyenv/bin:${PATH}"
export PYENV_ROOT="${HOME}/.pyenv"
eval "$(pyenv init -)"
# install Python 3.8.17
pyenv install 3.8.17
# make it available globally
pyenv global system 3.8.17
安装
使用 pip
pip install failprint
使用pipx
python3.8 -m pip install --user pipx
pipx install failprint
用法
% poetry run failprint -h
usage: failprint [-h] [-c {stdout,stderr,both,none}] [-f {pretty,tap}] [-y | -Y] [-p | -P] [-q | -Q] [-s | -S] [-z | -Z] [-n NUMBER]
[-t TITLE]
COMMAND [COMMAND ...]
positional arguments:
COMMAND
optional arguments:
-h, --help show this help message and exit
-c {stdout,stderr,both,none}, --capture {stdout,stderr,both,none}
Which output to capture. Colors are supported with 'both' only, unless the command has a 'force color'
option.
-f {pretty,tap}, --format {pretty,tap}
Output format. Pass your own Jinja2 template as a string with '-f custom=TEMPLATE'. Available variables:
command, title (command or title passed with -t), code (exit status), success (boolean), failure (boolean),
number (command number passed with -n), output (command output), nofail (boolean), quiet (boolean), silent
(boolean). Available filters: indent (textwrap.indent).
-y, --pty Enable the use of a pseudo-terminal. PTY doesn't allow programs to use standard input.
-Y, --no-pty Disable the use of a pseudo-terminal. PTY doesn't allow programs to use standard input.
-p, --progress Print progress while running a command.
-P, --no-progress Don't print progress while running a command.
-q, --quiet Don't print the command output, even if it failed.
-Q, --no-quiet Print the command output when it fails.
-s, --silent Don't print anything.
-S, --no-silent Print output as usual.
-z, --zero, --nofail Don't fail. Always return a success (0) exit code.
-Z, --no-zero, --strict
Return the original exit code.
-n NUMBER, --number NUMBER
Command number. Useful for the 'tap' format.
-t TITLE, --title TITLE
Command title. Default is the command itself.
from failprint.runners import run
cmd = "echo hello"
exit_code = run(
cmd, # str, list of str, or Python callable
args=None, # args for callable
kwargs=None, # kwargs for callable
number=1, # command number, useful for tap format
capture=None, # stdout, stderr, both, none, True or False
title=None, # command title
fmt=None, # pretty, tap, or custom="MY_CUSTOM_FORMAT"
pty=False, # use a PTY
progress=True, # print the "progress" template before running the command
nofail=False, # always return zero
quiet=False, # don't print output when the command fails
silent=False, # don't print anything
)
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分布
failprint-1.0.2.tar.gz (19.5 kB 查看哈希值)
构建分布
failprint-1.0.2-py3-none-any.whl (16.7 kB 查看哈希值)