Skip to content

Commit 0b5eb13

Browse files
committed
CLI for ease of testing.
1 parent ab9abc0 commit 0b5eb13

9 files changed

Lines changed: 750 additions & 0 deletions

File tree

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changelog
44
0.12 — unreleased
55
-----------------
66

7+
- New ``pystrich`` console script with a subcommand per format and PNG /
8+
SVG / EPS / ASCII / terminal / DXF output. See :doc:`cli`.
79
- Data Matrix: :class:`~pystrich.datamatrix.DataMatrixData` now expects
810
either an ``encoding=`` argument or ``auto_encoding=True`` to be set
911
on construction. The new ``auto_encoding=True`` flag picks the

docs/cli.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Command-line interface
2+
======================
3+
4+
Installing pyStrich exposes a ``pystrich`` console script with a subcommand
5+
per format and PNG / SVG / EPS / ASCII / terminal / DXF output.
6+
7+
.. code-block:: console
8+
9+
$ pystrich qrcode --text "https://en.wikipedia.org/wiki/Jasper,_Missouri" -o jasper.svg
10+
$ pystrich code128 --text "Dalton" -o dalton.png
11+
$ pystrich ean13 --text "5050070007664" -o ean13.png
12+
$ echo "DLB 573" | pystrich code39 -o code39.png
13+
$ pystrich datamatrix --text "Rausschmeißer" # terminal preview
14+
15+
The last example produces:
16+
17+
.. literalinclude:: examples/datamatrix-rausschmeisser-terminal.txt
18+
:language: text
19+
:class: terminal-art
20+
21+
Reference
22+
---------
23+
24+
.. argparse::
25+
:module: pystrich.cli
26+
:func: _build_parser
27+
:prog: pystrich
28+
29+
Format auto-detection
30+
---------------------
31+
32+
The output format is auto-detected from the ``-o`` filename
33+
(``.png``, ``.svg``, ``.eps``, ``.dxf``); without ``-o`` it defaults to
34+
``terminal`` for 2D formats when stdout is a TTY. Piped or redirected
35+
output without an explicit ``-t`` is rejected, to avoid dumping binary
36+
into the next tool by accident.
37+
38+
GS1 Data Matrix from the shell
39+
------------------------------
40+
41+
GS1 Data Matrix uses ASCII with ``FNC1`` markers separating application
42+
identifiers and their values. ``--substitute-with-fnc1`` lets you build
43+
that input from a shell-friendly string:
44+
45+
.. code-block:: console
46+
47+
$ pystrich datamatrix \
48+
--text "|0105050070007664" \
49+
--substitute-with-fnc1 "|" \
50+
-o gs1.png
51+
52+
See :doc:`datamatrix` for the full encoding discussion.
53+
54+
Limitations
55+
-----------
56+
57+
The CLI doesn't expose every Python-API knob. Reach for the Python API for
58+
1D label fonts, custom borders, EAN-13's ``first_digit_y_offset``, or the
59+
deprecated DataMatrix ``compat`` encoding.
60+
61+
API
62+
---
63+
64+
.. automodule:: pystrich.cli
65+
:members: main

docs/conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"sphinx.ext.intersphinx",
2121
"sphinx.ext.viewcode",
2222
"sphinx_copybutton",
23+
"sphinxarg.ext",
2324
]
2425

2526
copybutton_prompt_text = r">>> |\.\.\. |\$ "
@@ -77,6 +78,12 @@ def _generate_example_images(app):
7778
DataMatrixEncoder(pystrich_url).get_terminal_art(ansi_bg=False),
7879
encoding="utf-8",
7980
)
81+
(out / "datamatrix-rausschmeisser-terminal.txt").write_text(
82+
DataMatrixEncoder(
83+
DataMatrixData("Rausschmeißer", auto_encoding=True)
84+
).get_terminal_art(ansi_bg=False),
85+
encoding="utf-8",
86+
)
8087

8188
if app.builder.name != "html":
8289
# Non-HTML builders parse .. image:: directives but don't render the

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Guides
7474
.. toctree::
7575
:maxdepth: 1
7676

77+
cli
7778
recipes
7879
printing
7980

docs/recipes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Recipes
33

44
Common patterns for using pyStrich in real applications.
55

6+
For one-off generation from a shell, see :doc:`cli`.
7+
68
Serving barcodes from a web request
79
-----------------------------------
810

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Homepage = "https://github.com/mmulqueen/pyStrich"
3737
Repository = "https://github.com/mmulqueen/pyStrich"
3838
Documentation = "https://www.method-b.uk/pyStrich/docs/"
3939

40+
[project.scripts]
41+
pystrich = "pystrich.cli:main"
42+
4043
[dependency-groups]
4144
dev = [
4245
"pytest>=8.2.2",
@@ -49,6 +52,7 @@ docs = [
4952
"sphinx>=8.1",
5053
"furo>=2024.8.6",
5154
"sphinx-copybutton>=0.5",
55+
"sphinx-argparse>=0.5",
5256
]
5357

5458
[build-system]

0 commit comments

Comments
 (0)