Using click 6.7 + Python 3.6.0 :: Anaconda custom (64-bit)
If I create option with parameters type=click.File('w') default='-' Then the value defaults to sys.stdout. But when I create it with type=click.File('x') default='-' it defaults to sys.stdin. In my opinion it should default also to sys.stdout becase x file mode is also for writing (with exclusive file creation).
Run this script for proof:
#!/usr/bin/env python3
import sys
import click
@click.command()
@click.option('--file', '-f', type=click.File('x'), default='-')
def cli(file):
print('stdin:', file == sys.stdin)
print('stdout:', file == sys.stdout)
if __name__ == '__main__':
cli()
Output is:
$ ./test.py
stdin: True
stdout: False
Using click 6.7 + Python 3.6.0 :: Anaconda custom (64-bit)
If I create option with parameters
type=click.File('w') default='-'Then the value defaults tosys.stdout. But when I create it withtype=click.File('x') default='-'it defaults tosys.stdin. In my opinion it should default also tosys.stdoutbecasexfile mode is also for writing (with exclusive file creation).Run this script for proof:
Output is: