summaryrefslogtreecommitdiffstats
path: root/third_party/python/Click/examples/inout
diff options
context:
space:
mode:
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
+ ''',
+)