failprint


Namefailprint JSON
Version 1.0.2 PyPI version JSON
download
home_page
SummaryRun a command, print its output only if it fails.
upload_time2023-09-18 13:51:29
maintainer
docs_urlNone
author
requires_python>=3.8
licenseISC
keywords cli failure output runner
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # failprint

[![ci](https://github.com/pawamoy/failprint/workflows/ci/badge.svg)](https://github.com/pawamoy/failprint/actions?query=workflow%3Aci)
[![documentation](https://img.shields.io/badge/docs-mkdocs%20material-blue.svg?style=flat)](https://pawamoy.github.io/failprint/)
[![pypi version](https://img.shields.io/pypi/v/failprint.svg)](https://pypi.org/project/failprint/)
[![gitpod](https://img.shields.io/badge/gitpod-workspace-blue.svg?style=flat)](https://gitpod.io/#https://github.com/pawamoy/failprint)
[![gitter](https://badges.gitter.im/join%20chat.svg)](https://gitter.im/failprint/community)

Run a command, print its output only if it fails.

Tired of searching the `quiet` options of your programs
to lighten up the output of your `make check` or `make lint` commands?

Tired of finding out that standard output and error are mixed up in some of them?

Simply run your command through `failprint`.
If it succeeds, nothing is printed.
If it fails, standard error is printed.
Plus other configuration goodies :wink:

## Example

You don't want to see output when the command succeeds.

![demo](demo.svg)

The task runner [`duty`](https://github.com/pawamoy/duty) uses `failprint`,
allowing you to define tasks in Python and run them with minimalist and beautiful output:

![demo_duty](demo_duty.svg)

## Requirements

failprint requires Python 3.8 or above.

<details>
<summary>To install Python 3.8, I recommend using <a href="https://github.com/pyenv/pyenv"><code>pyenv</code></a>.</summary>

```bash
# 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
```
</details>

## Installation

With `pip`:
```bash
pip install failprint
```

With [`pipx`](https://github.com/pipxproject/pipx):
```bash
python3.8 -m pip install --user pipx
pipx install failprint
```

## Usage

```console
% 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.
```

```python
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
)
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "failprint",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "cli failure output runner",
    "author": "",
    "author_email": "Timoth\u00e9e Mazzucotelli <pawamoy@pm.me>",
    "download_url": "https://files.pythonhosted.org/packages/84/81/97bdd09f438fb776686fc41a3f22634446f001a4f44e335f54907286c899/failprint-1.0.2.tar.gz",
    "platform": null,
    "description": "# failprint\n\n[![ci](https://github.com/pawamoy/failprint/workflows/ci/badge.svg)](https://github.com/pawamoy/failprint/actions?query=workflow%3Aci)\n[![documentation](https://img.shields.io/badge/docs-mkdocs%20material-blue.svg?style=flat)](https://pawamoy.github.io/failprint/)\n[![pypi version](https://img.shields.io/pypi/v/failprint.svg)](https://pypi.org/project/failprint/)\n[![gitpod](https://img.shields.io/badge/gitpod-workspace-blue.svg?style=flat)](https://gitpod.io/#https://github.com/pawamoy/failprint)\n[![gitter](https://badges.gitter.im/join%20chat.svg)](https://gitter.im/failprint/community)\n\nRun a command, print its output only if it fails.\n\nTired of searching the `quiet` options of your programs\nto lighten up the output of your `make check` or `make lint` commands?\n\nTired of finding out that standard output and error are mixed up in some of them?\n\nSimply run your command through `failprint`.\nIf it succeeds, nothing is printed.\nIf it fails, standard error is printed.\nPlus other configuration goodies :wink:\n\n## Example\n\nYou don't want to see output when the command succeeds.\n\n![demo](demo.svg)\n\nThe task runner [`duty`](https://github.com/pawamoy/duty) uses `failprint`,\nallowing you to define tasks in Python and run them with minimalist and beautiful output:\n\n![demo_duty](demo_duty.svg)\n\n## Requirements\n\nfailprint requires Python 3.8 or above.\n\n<details>\n<summary>To install Python 3.8, I recommend using <a href=\"https://github.com/pyenv/pyenv\"><code>pyenv</code></a>.</summary>\n\n```bash\n# install pyenv\ngit clone https://github.com/pyenv/pyenv ~/.pyenv\n\n# setup pyenv (you should also put these three lines in .bashrc or similar)\nexport PATH=\"${HOME}/.pyenv/bin:${PATH}\"\nexport PYENV_ROOT=\"${HOME}/.pyenv\"\neval \"$(pyenv init -)\"\n\n# install Python 3.8.17\npyenv install 3.8.17\n\n# make it available globally\npyenv global system 3.8.17\n```\n</details>\n\n## Installation\n\nWith `pip`:\n```bash\npip install failprint\n```\n\nWith [`pipx`](https://github.com/pipxproject/pipx):\n```bash\npython3.8 -m pip install --user pipx\npipx install failprint\n```\n\n## Usage\n\n```console\n% poetry run failprint -h\nusage: failprint [-h] [-c {stdout,stderr,both,none}] [-f {pretty,tap}] [-y | -Y] [-p | -P] [-q | -Q] [-s | -S] [-z | -Z] [-n NUMBER]\n                 [-t TITLE]\n                 COMMAND [COMMAND ...]\n\npositional arguments:\n  COMMAND\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -c {stdout,stderr,both,none}, --capture {stdout,stderr,both,none}\n                        Which output to capture. Colors are supported with 'both' only, unless the command has a 'force color'\n                        option.\n  -f {pretty,tap}, --format {pretty,tap}\n                        Output format. Pass your own Jinja2 template as a string with '-f custom=TEMPLATE'. Available variables:\n                        command, title (command or title passed with -t), code (exit status), success (boolean), failure (boolean),\n                        number (command number passed with -n), output (command output), nofail (boolean), quiet (boolean), silent\n                        (boolean). Available filters: indent (textwrap.indent).\n  -y, --pty             Enable the use of a pseudo-terminal. PTY doesn't allow programs to use standard input.\n  -Y, --no-pty          Disable the use of a pseudo-terminal. PTY doesn't allow programs to use standard input.\n  -p, --progress        Print progress while running a command.\n  -P, --no-progress     Don't print progress while running a command.\n  -q, --quiet           Don't print the command output, even if it failed.\n  -Q, --no-quiet        Print the command output when it fails.\n  -s, --silent          Don't print anything.\n  -S, --no-silent       Print output as usual.\n  -z, --zero, --nofail  Don't fail. Always return a success (0) exit code.\n  -Z, --no-zero, --strict\n                        Return the original exit code.\n  -n NUMBER, --number NUMBER\n                        Command number. Useful for the 'tap' format.\n  -t TITLE, --title TITLE\n                        Command title. Default is the command itself.\n```\n\n```python\nfrom failprint.runners import run\n\ncmd = \"echo hello\"\n\nexit_code = run(\n    cmd,            # str, list of str, or Python callable\n    args=None,      # args for callable\n    kwargs=None,    # kwargs for callable\n    number=1,       # command number, useful for tap format\n    capture=None,   # stdout, stderr, both, none, True or False\n    title=None,     # command title\n    fmt=None,       # pretty, tap, or custom=\"MY_CUSTOM_FORMAT\"\n    pty=False,      # use a PTY\n    progress=True,  # print the \"progress\" template before running the command\n    nofail=False,   # always return zero\n    quiet=False,    # don't print output when the command fails\n    silent=False,   # don't print anything\n)\n```\n",
    "bugtrack_url": null,
    "license": "ISC",
    "summary": "Run a command, print its output only if it fails.",
    "version": "1.0.2",
    "project_urls": {
        "Changelog": "https://pawamoy.github.io/failprint/changelog",
        "Discussions": "https://github.com/pawamoy/failprint/discussions",
        "Documentation": "https://pawamoy.github.io/failprint",
        "Funding": "https://github.com/sponsors/pawamoy",
        "Gitter": "https://gitter.im/failprint/community",
        "Homepage": "https://pawamoy.github.io/failprint",
        "Issues": "https://github.com/pawamoy/failprint/issues",
        "Repository": "https://github.com/pawamoy/failprint"
    },
    "split_keywords": [
        "cli",
        "failure",
        "output",
        "runner"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "964be1d7a88bcc9957416c3278400d0b22fe2d46ebfde960f5cc01ef7c4ee1ae",
                "md5": "a924edd5268b03ebb7e286459822b06e",
                "sha256": "111eb0b7f0ef8af4dc2826f57d8c99b3e63cde42f6f9a7b7f86f3f8d69cf4056"
            },
            "downloads": -1,
            "filename": "failprint-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a924edd5268b03ebb7e286459822b06e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 16685,
            "upload_time": "2023-09-18T13:51:27",
            "upload_time_iso_8601": "2023-09-18T13:51:27.149504Z",
            "url": "https://files.pythonhosted.org/packages/96/4b/e1d7a88bcc9957416c3278400d0b22fe2d46ebfde960f5cc01ef7c4ee1ae/failprint-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "848197bdd09f438fb776686fc41a3f22634446f001a4f44e335f54907286c899",
                "md5": "9a256c621d198aa2f0e0d66e4ec2b25a",
                "sha256": "ee27b21f2c4974a38d8b172d639b1ae8c9d07f66158774c78f1abfe69ae289e6"
            },
            "downloads": -1,
            "filename": "failprint-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "9a256c621d198aa2f0e0d66e4ec2b25a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 19458,
            "upload_time": "2023-09-18T13:51:29",
            "upload_time_iso_8601": "2023-09-18T13:51:29.431616Z",
            "url": "https://files.pythonhosted.org/packages/84/81/97bdd09f438fb776686fc41a3f22634446f001a4f44e335f54907286c899/failprint-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-18 13:51:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pawamoy",
    "github_project": "failprint",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "failprint"
}
        
Elapsed time: 0.15680s