Skip to content

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

@tkossak

Description

@tkossak

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions