Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File('x') should default to stdout not stdin #776

Closed
tkossak opened this issue May 3, 2017 · 0 comments · Fixed by #929
Closed

File('x') should default to stdout not stdin #776

tkossak opened this issue May 3, 2017 · 0 comments · Fixed by #929

Comments

@tkossak
Copy link

tkossak commented May 3, 2017

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant