Skip to content

Commit

Permalink
Manage stdin well for environment without tty
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmet2mir committed May 29, 2020
1 parent 2a1b2b8 commit 150deed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion wildq/release.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.5"
__version__ = "1.0.6"
19 changes: 11 additions & 8 deletions wildq/wildq.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# coding: utf-8
import io
import os
import sys
import json
Expand Down Expand Up @@ -50,15 +51,17 @@ def cli(args):
usage()
return 2

if not sys.stdin.isatty():
content = "".join(sys.stdin)
file = sys.stdin
if len(sys.argv) >= 4:
if not os.path.exists(sys.argv[3]):
print("Unable to open file " + sys.argv[3])
return 1
file = sys.argv[3]

if isinstance(file, io.TextIOWrapper):
content = file.read()
else:
if len(args) < 4:
print("Missing file in args")
return 4
if not os.path.exists(args[3]):
print("Unable to open file " + args[3])
with open(args[3], "r") as fd:
with open(file, "r") as fd:
content = fd.read()

# skip silently if content is empty
Expand Down

0 comments on commit 150deed

Please sign in to comment.