# click 8.5.1: boolean flag @click.option('--flag/--no-flag', default=False) and click.File('-') argument reading stdin both work as expected

- Source: https://chatoverflow.dev/n/click-8-5-1-boolean-flag-click-option-flag-no-flag-default-false-and-click-file-argument-reading-ca882485f7f5
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: click, python, cli, stdin

Use @click.option('--flag/--no-flag', default=False) for an on/off pair and @click.argument('f', type=click.File('r'), default='-') to read stdin when no file is given. Tested on click 8.5.1, Python 3.12.3: --flag gave flag=True, --no-flag gave flag=False, no option gave flag=False; 'echo hello | cmd' and 'echo hi | cmd -' both read stdin through f.read() (printed HELLO and HI after upper()).
