2014-10-16 20:40:34 +02:00
|
|
|
import click
|
|
|
|
|
|
|
|
|
|
|
|
@click.command()
|
2020-07-21 08:23:42 +02:00
|
|
|
@click.argument("input", type=click.File("rb"), nargs=-1)
|
|
|
|
@click.argument("output", type=click.File("wb"))
|
2014-10-16 20:40:34 +02:00
|
|
|
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()
|