fune/third_party/python/Click/examples/inout/inout.py
Dave Hunt 1b8dbe2a78 Bug 1490253 - Vendor pip-tools 3.0.0 and dependencies; r=ahal
Differential Revision: https://phabricator.services.mozilla.com/D7869

--HG--
extra : moz-landing-system : lando
2018-10-05 18:46:07 +00:00

30 lines
722 B
Python

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()