Last active
February 18, 2025 07:57
-
-
Save esmaeelE/195068619b8f1d90cc474fa174b73b1e to your computer and use it in GitHub Desktop.
click cli read from stdin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/env/bin/python3 | |
import click | |
import sys | |
@click.group() | |
def cli(): | |
pass | |
@cli.command() | |
@click.option('--compose-file', | |
help='compose file to work with', | |
type=click.File('r'), | |
default=sys.stdin) | |
def secret_hash_ini(compose_file): | |
with compose_file: | |
data = compose_file.read() | |
print(data, end='') | |
if __name__ == '__main__': | |
cli() | |
# Run | |
# echo thisistest | ./run.py secret-hash-ini | |
# based on [larsks' aswer on SO](https://stackoverflow.com/a/59830073) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment