summaryrefslogtreecommitdiffstats
path: root/third_party/python/Click/examples/inout
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/python/Click/examples/inout
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/python/Click/examples/inout')
-rw-r--r--third_party/python/Click/examples/inout/README10
-rw-r--r--third_party/python/Click/examples/inout/inout.py30
-rw-r--r--third_party/python/Click/examples/inout/setup.py15
3 files changed, 55 insertions, 0 deletions
diff --git a/third_party/python/Click/examples/inout/README b/third_party/python/Click/examples/inout/README
new file mode 100644
index 0000000000..6309bc873e
--- /dev/null
+++ b/third_party/python/Click/examples/inout/README
@@ -0,0 +1,10 @@
+$ inout_
+
+ inout is a simple example of an application that
+ can read from files and write to files but also
+ accept input from stdin or write to stdout.
+
+Usage:
+
+ $ pip install --editable .
+ $ inout input_file.txt output_file.txt
diff --git a/third_party/python/Click/examples/inout/inout.py b/third_party/python/Click/examples/inout/inout.py
new file mode 100644
index 0000000000..b93f306629
--- /dev/null
+++ b/third_party/python/Click/examples/inout/inout.py
@@ -0,0 +1,30 @@
+import click
+
+
+@click.command()
+@click.argument('input', type=click.File('rb'), nargs=-1)
+@click.argument('output', type=click.File('wb'))
+def cli(input, output):
+ """This script works similar to the Unix `cat` command but it writes
+ into a specific file (which could be the standard output as denoted by
+ the ``-`` sign).
+
+ \b
+ Copy stdin to stdout:
+ inout - -
+
+ \b
+ Copy foo.txt and bar.txt to stdout:
+ inout foo.txt bar.txt -
+
+ \b
+ Write stdin into the file foo.txt
+ inout - foo.txt
+ """
+ for f in input:
+ while True:
+ chunk = f.read(1024)
+ if not chunk:
+ break
+ output.write(chunk)
+ output.flush()
diff --git a/third_party/python/Click/examples/inout/setup.py b/third_party/python/Click/examples/inout/setup.py
new file mode 100644
index 0000000000..5c613646e2
--- /dev/null
+++ b/third_party/python/Click/examples/inout/setup.py
@@ -0,0 +1,15 @@
+from setuptools import setup
+
+setup(
+ name='click-example-inout',
+ version='0.1',
+ py_modules=['inout'],
+ include_package_data=True,
+ install_requires=[
+ 'click',
+ ],
+ entry_points='''
+ [console_scripts]
+ inout=inout:cli
+ ''',
+)