Skip to content

Commit a2c09de

Browse files
committed
feat(cli): add a bar shorthand for the pv-style command
pip install progressbar2 now also puts a three-keystroke bar command on the path, the same progressbar.__main__:main entry point, so pipelines read tar cf - src/ | bar --bytes --rate > backup.tar. The README, CLI reference, and the readme/cli example docstring teach it, and a packaging test pins both console scripts to the same entry point.
1 parent 8c0039a commit a2c09de

5 files changed

Lines changed: 31 additions & 12 deletions

File tree

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,16 +315,18 @@ Errors, timeouts, pools, and the decorator form are covered in the
315315

316316
## Replace pv on the command line
317317

318-
Installing the package also installs a `progressbar` command, a Python
319-
implementation of the classic Unix `pv`: it copies input to output and
320-
draws the transfer on stderr, so it drops into pipelines:
318+
Installing the package also installs a `progressbar` command and its
319+
`bar` shorthand, a Python implementation of the classic Unix `pv`: it
320+
copies input to output and draws the transfer on stderr, so it drops
321+
into pipelines:
321322

322323
```sh
323324
# File to file, with percentage, timer, ETA, rate and byte count:
324325
progressbar --progress --timer --eta --rate --bytes data.bin -o copy.bin
325326

326-
# In a pipeline, data on stdout and progress on stderr:
327-
tar cf - src/ | progressbar --bytes --rate > backup.tar
327+
# In a pipeline, data on stdout and progress on stderr. `bar` is the
328+
# same command with three keystrokes:
329+
tar cf - src/ | bar --bytes --rate > backup.tar
328330
```
329331

330332
![the progressbar command copying a file with percentage, timer, ETA, rate and byte count displays](https://raw.githubusercontent.com/wolph/python-progressbar/develop/docs/_static/demos/readme-cli.svg)

docs/examples/readme/cli.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""The `progressbar` command is a `pv` replacement for pipes and files.
22
3-
Installing the package puts a `progressbar` executable on the path
4-
(`python -m progressbar` is the same program), a Python implementation
5-
of the classic Unix `pv`: it copies input to output while drawing
6-
transfer progress on stderr. This example drives it in-process, moving
7-
4 MiB at a rate-limited 2 MiB/s with the percentage, timer, ETA, rate
8-
and byte-counter displays turned on.
3+
Installing the package puts a `progressbar` executable on the path,
4+
with `bar` as its pipeline shorthand (`python -m progressbar` is the
5+
same program), a Python implementation of the classic Unix `pv`: it
6+
copies input to output while drawing transfer progress on stderr.
7+
This example drives it in-process, moving 4 MiB at a rate-limited
8+
2 MiB/s with the percentage, timer, ETA, rate and byte-counter
9+
displays turned on.
910
"""
1011

1112
import pathlib

docs/reference/cli.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
====================
44

55
Installing ``progressbar2`` installs a ``progressbar`` console script
6-
(:py:func:`progressbar.__main__.main`). It reads from stdin (or one or more
6+
(:py:func:`progressbar.__main__.main`), plus ``bar`` as a shorthand for
7+
the same command in pipelines. It reads from stdin (or one or more
78
files), writes the same bytes through to stdout (or a file), and draws a
89
progress bar on stderr while it does -- a small, Python-native reimplementation
910
of the ``pv`` ("pipe viewer") command. Per its own ``--help`` text it is

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ repository = 'https://github.com/wolph/python-progressbar/'
116116

117117
[project.scripts]
118118
progressbar = 'progressbar.__main__:main'
119+
# Shorthand for pipelines: `bar data.bin -o copy.bin`.
120+
bar = 'progressbar.__main__:main'
119121

120122
[project.optional-dependencies]
121123
# Optional native iterator accelerator. When installed it is detected and used

tests/test_progressbar_command.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io
2+
import pathlib
23

34
import pytest
45

@@ -288,3 +289,15 @@ def test_main_empty_file_has_known_size(tmp_path, recorded_bars) -> None:
288289
main.main([str(file), '-o', str(tmp_path / 'out.bin')])
289290

290291
assert recorded_bars[0].init_kwargs.get('max_value') == 0
292+
293+
294+
def test_console_scripts_include_the_bar_shorthand() -> None:
295+
# Both the canonical `progressbar` command and its `bar` shorthand
296+
# must point at the same entry point: the shorthand exists purely
297+
# for shorter pipelines (`bar data.bin -o copy.bin`).
298+
pyproject = (
299+
pathlib.Path(__file__).parents[1] / 'pyproject.toml'
300+
).read_text(encoding='utf-8')
301+
302+
assert "progressbar = 'progressbar.__main__:main'" in pyproject
303+
assert "bar = 'progressbar.__main__:main'" in pyproject

0 commit comments

Comments
 (0)