Skip to content

Commit

Permalink
proper tty handling for pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
akarve committed Jun 10, 2024
1 parent b38d80e commit fe43add
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ check::
poetry run black . --check
poetry run isort . --check
poetry run flake8 . --ignore=E501,W503
bash -n *.sh

lint::
isort .
Expand Down
10 changes: 3 additions & 7 deletions src/bipsea/bipsea.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging
import re
import select
import sys

import click
Expand Down Expand Up @@ -307,12 +306,9 @@ def no_empty_param(name: str, val, msg="Must not be empty."):


def try_for_pipe_input():
stdin, _, _ = select.select([sys.stdin], [], [], TIMEOUT)
if stdin:
lines = sys.stdin.readlines()
if lines:
# get just the last line because there might be a warning above
return lines[-1].strip()
if not sys.stdin.isatty():
return sys.stdin.read().strip()
return ""


if __name__ == "__main__":
Expand Down
20 changes: 14 additions & 6 deletions test-readme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,28 @@ poetry run bipsea validate --help
poetry run bipsea xprv --help
poetry run bipsea derive --help

poetry run bipsea mnemonic | poetry run bipsea validate
poetry run bipsea mnemonic | poetry run bipsea validate | poetry run bipsea xprv | bipsea derive -a mnemonic -n 12

poetry run bipsea xprv -m "$MNEMONIC" | poetry run bipsea derive -a mnemonic -n 12
poetry run bipsea mnemonic -t jpn -n 15

poetry run bipsea mnemonic -n 12 --pretty

poetry run bipsea mnemonic -t spa -n 12 | poetry run bipsea validate -f spa

poetry run bipsea mnemonic | poetry run bipsea validate

poetry run bipsea mnemonic | poetry run bipsea validate | poetry run bipsea xprv

poetry run bipsea xprv -m "$MNEMONIC" | poetry run bipsea derive -a mnemonic -n 12

poetry run bipsea validate -f free -m "123456123456123456" | poetry run bipsea xprv

poetry run bipsea validate -f free -m "$(cat input.txt)"

poetry run bipsea xprv -m "$MNEMONIC" | poetry run bipsea derive -a base85
poetry run bipsea validate -m $MNEMONIC | poetry run bipsea xprv | poetry run bipsea derive -a base85

poetry run bipsea xprv -m "$MNEMONIC" | poetry run bipsea derive -a mnemonic -t jpn -n 12
poetry run bipsea validate -m "$MNEMONIC" | poetry run bipsea xprv | poetry run bipsea derive -a mnemonic -t jpn -n 12

poetry run bipsea xprv -m "$MNEMONIC" | poetry run bipsea derive -a drng -n 1000
poetry run bipsea validate -m "$MNEMONIC" | poetry run bipsea xprv | poetry run bipsea derive -a drng -n 1000

poetry run bipsea xprv -m "$MNEMONIC" | poetry run bipsea derive -a dice -n 100 -s 6
poetry run bipsea validate -m "$MNEMONIC" | poetry run bipsea xprv | poetry run bipsea derive -a dice -n 100 -s 6

0 comments on commit fe43add

Please sign in to comment.